【问题标题】:PrimeFaces template navigation using <p:MenuItem>PrimeFaces 模板导航使用 <p:MenuItem>
【发布时间】:2014-05-02 16:31:11
【问题描述】:

我已经在 stackoverflow 上阅读了几个关于这个问题的帖子,但我还没有找到解决方案。

在我的 index.xhtml 模板中,我定义了一个导航和一个内容布局单元。 菜单是基本的&lt;p:menu&gt; 菜单。

用另一个网站填充内容面板,例如page1.xhtml 使用&lt;p:commandButton&gt; 效果很好。 使用&lt;p:menuItem&gt; 导航不起作用。我尝试设置ajax="false",将action 更改为actionListener。没有什么帮助。秘密在哪里? :)

index.xhtml:

<h:body>
    <p:layout fullPage="true">
        <p:layoutUnit position="north" size="50" id="top">
            <h:form>
                <ui:include src="/template/header.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="south" size="50">
            <h:form>
                <ui:include src="/template/footer.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="west" size="350" >
            <h:form>
                <ui:include src="/template/mainmenu.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="center" >
            <h:panelGroup id="contentPanel">
                <ui:include src="#{navController.pageName}.xhtml" />
            </h:panelGroup>
        </p:layoutUnit>
    </p:layout>
</h:body>

ma​​inmenu.xhtml:

<h:body>
    <h:form id="formMainMenu">      

            <p:menu>            
                <p:submenu label="Menu">
                    <p:menuitem value="Link I" action="#{navController.navigateTo}" ajax="false" update=":contentPanel" icon="ui-icon-disk">
                        <f:param name="navParam" value="/pages/page1" />
                    </p:menuitem>
                </p:submenu>
            </p:menu>

这有效:

            <p:commandButton value="Link I" action="#{navController.navigateTo}" update=":contentPanel">
                <f:param name="navParam" value="/pages/page1" />
            </p:commandButton>

    </h:form>
</h:body>

navController导航方式:

public void navigateTo() 
{
     String target = acesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("navParam");
     setPageName(target);
}

【问题讨论】:

  • hmm.. 似乎连像&lt;p:menuitem value="Display Message" actionListener="#{navController.message}" update="messages" icon="ui-icon-disk" /&gt; 这样的基本actionListener 也没有被调用。我处于调试模式,它永远不会跳转到消息方法:/当我把它放入 时它就可以工作了..
  • 在直接运行 mainmenu.xhtml 时,menuItem 上的 actionListener 适用于基本的actionListener="#{navController.message}" - 而不是从 index.xhtml。

标签: jsf primefaces navigation menuitem


【解决方案1】:

(Question edit converted to an answer)

OP 写道:

hmm.. 好像连基本的actionListener 都喜欢

<p:menuitem value="Display Message" actionListener="#{navController.message}" update="messages" icon="ui-icon-disk" />

未被调用。我处于调试模式,它永远不会跳转到消息方法:/当我将它放入 &lt;p:commandButton&gt; 时,它就可以工作..

menuItem 上的actionListener 在直接运行mainmenu.xhtml 时适用于基本actionListener="#{navController.message}" - 而不是来自index.xhtml

我终于通过从我的mainmenu.xhtml 中删除&lt;h:form id="formMainMenu"&gt; &lt;/h:form&gt; 标签解决了这个问题。

解释为什么这适用于commandButton 但不适用于menuItem 会很棒!谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多