我有一个这样的PrimeFaces 3.4菜单栏:
<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>
后台bean是这样的
@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";
}
}
问题是它不工作,没有例外,什么都没有。我最初试着把动作写成这样……把goNav改成void…没什么
任何想法?提前感谢瑞克
Primefaces菜单项有一个url属性:
url:菜单项被点击时导航的url。
如果你不使用"url",但想要使用"action",那么请记住你正在做一个post request。
在这种情况下,您应该
- 在返回字符串中添加?faces-redirect=true,如"test.xhtml?"faces-redirect = true "
- 在菜单项中设置ajax=false,比如
看这个来自质面的首席开发者的回答
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;
}