使用MenuItem的PrimeFaces导航 [英] PrimeFaces navigation using MenuItem

查看:99
本文介绍了使用MenuItem的PrimeFaces导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PrimeFaces 3.4菜单栏,如下所示:

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>

背景豆是这样的

@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 ...什么都没有.

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

推荐答案

Primefaces菜单项在这种情况下具有url属性:

Primefaces menuitem has a url attribute for this case:

url:单击菜单项时要浏览的网址.

url: Url to be navigated when menuitem is clicked.

如果您不使用"url",但想使用"action",那么请记住您正在执行发布请求.

If you are not using "url" but want to go with "action" then remember that you are doing a post request.

在这种情况下,您应该

  1. 在返回的字符串中添加?faces-redirect = true,例如"test.xhtml?faces-redirect = true"
  2. 在菜单项中设置ajax = false,例如

请参阅Primefaces首席开发人员的答案

See this answer from the lead developer of primefaces

这篇关于使用MenuItem的PrimeFaces导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆