【问题标题】:JSF and Primefaces conditional navigation [duplicate]JSF 和 Primefaces 条件导航 [重复]
【发布时间】:2014-09-20 09:10:24
【问题描述】:

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

代码如下:

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

【问题讨论】:

    标签: javascript jsf primefaces navigation


    【解决方案1】:

    例如,您可以使用action(在&lt;h:form&gt; 内)创建一个commandButton。根据属性consolecity 的值,从该操作返回“page1.xhtml”或“page2.xhtml”。

    喜欢(未经测试):

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

    【讨论】:

    • 谢谢,但它不起作用。我做错了什么。在托管 bean 选项中应该声明为公共字符串,对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 2016-10-30
    相关资源
    最近更新 更多