I am developing a web application using JSF and Primefaces. I want o show the following menu and depending on the choosen option go to one page or another.
XHTML code:
You might process the value of car
via an AJAX call and redirect the response from your bean class.
<p:selectOneMenu id="car" value="#{selectOneMenuView.car}">
<f:selectItem itemLabel="Select One" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{selectOneMenuView.cars}" />
<p:ajax listener="#{selectOneMenuView.someAction()"
process="@this" partialSubmit="true" />
</p:selectOneMenu>
And within your bean class something like
public void someAction() {
String location = "page"+car+".xhtml";
FacesContext.getCurrentInstance()
.getExternalContext()
.redirect(location)
;
}
}
I would append an AJAX on change event to the selectOneMenu
which calls a method on your bean and redirects through it similar to a combination of the respective accepted answers of selectOneMenu ajax events (AJAX event) and Sending a redirect from inside an ajax listener method (redirect).