Jsf redirect to new window

La Chamelle picture La Chamelle · Feb 9, 2011 · Viewed 7.1k times · Source

i'm making a JSF2.0 project using mojarra primefaces tomcat6.x.

I made a select list and when i select item of the list i want to redirect to the selected url. It can be an internal URL.

It's work but i want to know if it's possible to redirect in new window.

I have the following code JSF:

        <h:form>
            <h:selectOneMenu onchange="this.form.submit();" valueChangeListener="#{wagent.selectBusinessTravelLink}">
                <f:selectItem itemLabel="#{msg['form.select.defaultValue']}" itemValue="" noSelectionOption="true"/>
                <f:selectItems value="#{wagent.businessTravelLinks}" var="bLinkItem" itemLabel="#{bLinkItem.label}" itemValue="#{bLinkItem.id}" />
            </h:selectOneMenu>
        </h:form>

Java:

   public void selectBusinessTravelLink(ValueChangeEvent event) {
// some stuff
FacesContext.getCurrentInstance().getExternalContext().redirect(targetUrl);
}

Answer

BalusC picture BalusC · Feb 9, 2011

Use JavaScript's window.open() function rather than form.submit() during the change event.

Assuming that the select item values are fullworthy URL's, here's an example:

<h:selectOneMenu onchange="window.open(this.options[this.selectedIndex].value)">