JSF Primefaces selectonemenu page navigation

后端 未结 2 515
闹比i
闹比i 2021-01-28 11:57

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:

相关标签:
2条回答
  • 2021-01-28 12:53

    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)
            ;
        }
    }
    
    0 讨论(0)
  • 2021-01-28 12:58

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

    0 讨论(0)
提交回复
热议问题