Reputation: 455
I have a PrimeFaces 3.4 Menubar like this:
<h:form>
<p:menubar>
<p:submenu label="File">
<p:submenu label="New">
<p:menuitem value="Go" id="page1LinkID" action="#{navBean.goNav}">
<f:param id="page1ParamID" name="pageViewID" value="Page1"/>
</p:menuitem>
<p:menuitem value="Other" url="#"/>
</p:submenu>
</p:submenu>
</p:menubar>
</h:form>
the backing bean is like this
@ManagedBean
@RequestScoped
public class navBean {
/**
* Creates a new instance of navBean
*/
private String includedPage = "contentMain.xhtml";
public navBean() {
}
public String getPage(){
return includedPage;
}
public void setPageName(){
this.includedPage = includedPage;
}
public String goNav() {
FacesContext context = FacesContext.getCurrentInstance();
String selectedPageViewId = context.getExternalContext().getRequestParameterMap().get("pageViewId");
if (selectedPageViewId.equalsIgnoreCase("page1")){
includedPage = "test.xhtml";
}
}
Problem is it does not work, no exceptions nothing. I originally tried putting the action into like this... Changing goNav to void...nothing.
Any Ideas? Thanks In Advance Rick
Upvotes: 4
Views: 24340
Reputation: 5619
Primefaces menuitem has a url attribute for this case:
url: Url to be navigated when menuitem is clicked.
If you are not using "url" but want to go with "action" then remember that you are doing a post request.
In this case you should either
See this answer from the lead developer of primefaces
Upvotes: 7
Reputation: 164
try this
public String goNav() {
FacesContext context = FacesContext.getCurrentInstance();
String selectedPageViewId = context.getExternalContext().getRequestParameterMap().get("pageViewId");
if (selectedPageViewId.equalsIgnoreCase("page1")){
includedPage = "test.xhtml?redirect=true";
}
return includedPage;
}
Upvotes: 0