2014-09-20 98 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