0

I am using jsf 2.2 and primefaces to develop a web application. I want depending on the different options the user chooses go to one page or another. How can I do if the user chooses the console PS4 and the city London go to page1.xhtml, and if he chooses console xbox and city paris go to page2.xhtml ?

Here is the code:

<h:form>
    <h3 style="margin-top:0">Basic</h3>
    <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
        <p:outputLabel for="console" value="Console:" />
        <p:selectOneRadio id="console" value="#{radioView.console}">
            <f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
            <f:selectItem itemLabel="PS4" itemValue="PS+" />
            <f:selectItem itemLabel="Wii U" itemValue="Wii U" />
        </p:selectOneRadio>
    </h:panelGrid>

  <h3 style="margin-top:0">Basic</h3>
    <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
        <p:outputLabel for="city" value="city:" />
        <p:selectOneRadio id="city" value="#{radioView.city}">
            <f:selectItem itemLabel="London" itemValue="london" />
            <f:selectItem itemLabel="Paris" itemValue="paris" />
            <f:selectItem itemLabel="NY" itemValue=ny" />
        </p:selectOneRadio>
    </h:panelGrid>
william
  • 103
  • 1
  • 2
  • 9

1 Answers1

0

You can for example create a commandButton with an action (inside the <h:form>). From this action you return either "page1.xhtml" or "page2.xhtml" depending on the values of the properties console and city.

Like (untested):

<p:commandButton value="Go!" action="#{radioView.gotoNextPage}" />

public String gotoNextPage() {
    if ("PS4".equals(console) && "london".equals(city)) // It has value "PS+" but I expect it's an error
        return "page1.xhtml";
    else if ("Xbox One".equals(console) && "paris".equals(city))
        return "page2.xhtml";
    else if ........
}
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
  • Thanks, but it doesnt work. I am doing something wrong. In the managed bean option should be declared like a public String, am I right? – william Sep 20 '14 at 16:56