2014-09-20 97 views
0

我正在使用jsf 2.2和primefaces开发一个web应用程序。我希望根据用户选择的不同选项转到一个页面或另一个页面。如果用户选择控制台PS4和伦敦城市转到page1.xhtml,并且他选择控制台xbox和城市巴黎转到page2.xhtml,我该怎么办?JSF和Primefaces条件导航

下面是代码:

<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> 

回答

0

例如,您可以创建具有action(在<h:form>内)一commandButton。根据此操作,您将返回“page1.xhtml”或“page2.xhtml”,具体取决于属性consolecity的值。

赞(未经测试):

<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 ........ 
} 
+0

谢谢,但它不工作。我做错了什么。在托管bean选项中应该声明为公共字符串,对吗? – william 2014-09-20 16:56:28