来自< p:menuitem>的链接某些< p:tab> [英] link from <p:menuitem> to certain <p:tab>

查看:67
本文介绍了来自< p:menuitem>的链接某些< p:tab>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想从菜单栏链接到某些选项卡,但总是第一个选项卡被激活,我尝试了StackOverflow的许多解决方案,但没有任何效果.我认为问题是我使用了preRenderView.我希望有人可以帮助我:)

Hi guys I want to link from my Menubar to certain Tab, but always the first tab is activated I tried lot of solutions from StackOverflow but nothing works. I think the problems is that i use a preRenderView. I hope someone can help me :)

我使用jsf 2.1和primefaces 3.5

I use jsf 2.1 and primefaces 3.5

菜单栏的代码

  <p:menubar >
       <p:submenu  label="Taskbox" >
            <p:menuitem value="Inbox" url="taskbox.xhtml" />
            <p:menuitem value="Sent" url="taskbox.xhtml#sentTab"/>
            <p:menuitem value="Trash" url="taskbox.xhtml" onclick="tabPanel.select(3)"/>
            <p:menuitem value="New Message" url="#"/>
       </p:submenu>          
    </p:menubar>

标签的邮政编码

<ui:composition template="/META-INF/templates/templateContentSplit.xhtml">

        <ui:define name="metadata">
            <f:metadata>
                <f:event type="preRenderView" listener="#{taskboxBean.initPage}" />
            </f:metadata>
        </ui:define>
<ui:define name="metadata">
            <f:metadata>
                <f:event type="preRenderView" listener="#{taskboxBean.initPage}" />
            </f:metadata>
        </ui:define>

        <ui:define name="title">
            <h:outputText value="Taskbox" />
        </ui:define>
        <ui:define name="contentLeft">
            <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet" />
            <h:form id="postForm">

                <p:tabView id="tabViewPosts" widgetVar="tabPanel">
                    <p:tab title="Inbox" id="inboxTab">
                        <ui:include src="/user/inboxTaskbox.xhtml" />
                    </p:tab>
                    <p:tab title="Sent" id="sentTab">
                        <ui:include src="/user/sentTaskbox.xhtml" />
                    </p:tab>
                    <p:tab title="Trash" id="trashTab">
                        <ui:include src="/user/trashTaskbox.xhtml" />
                    </p:tab>
                </p:tabView>
            </h:form>
        </ui:define>

        <ui:define name="contentRight">
            <h:form id="contentForm">
                <ui:include src="/user/detailTaskbox.xhtml" />
            </h:form>
        </ui:define>

    </ui:composition>

推荐答案

对于您的< p:menuitem/> ,请使用成果属性,该属性指定导航而不是 url 的情况下,它应与绝对而非JSF相关的url一起使用.在这里,您有一个基本的解释案例,基于@Daniel Camargo的建议代码:

For your <p:menuitem /> use an outcome attribute, which specifies the navigation case, instead of url, that's intended to be used with an absolute and not JSF related url. Here you've got a basic explanation case, based in @Daniel Camargo's suggested code:

tabs.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head />

<h:body>
    <f:metadata>
        <f:viewParam name="index" value="#{index}" />
        <f:event type="preRenderView" listener="#{bean.initPage}" />
    </f:metadata>

    <h:form>
        <p:menubar>
            <p:submenu label="Taskbox">
                <!-- Different ways of passing the view param -->
                <p:menuitem value="Inbox" outcome="tabs?index=0" />
                <p:menuitem value="Sent" outcome="tabs.xhtml?index=1" />
                <p:menuitem value="Trash" outcome="tabs">
                    <f:param name="index" value="2" />
                </p:menuitem>
                <!-- External url -->
                <p:menuitem value="Google" url="http://www.google.com"
                    target="_blank" />
            </p:submenu>
        </p:menubar>
    </h:form>

    <h:form id="postForm">
        <p:tabView id="tabViewPosts" widgetVar="tabPanel"
            activeIndex="#{index}">
            <p:tab title="Inbox" id="inboxTab">
            A
        </p:tab>
            <p:tab title="Sent" id="sentTab">
            B
        </p:tab>
            <p:tab title="Trash" id="trashTab">
            C
        </p:tab>
        </p:tabView>
    </h:form>
</h:body>
</html>

请注意 outcome 属性,在此让JSF Servlet评估目标URL.基本上,值为 tabs 的结果将在客户端显示为 basePath/tabs.xhtml .因此,基本上,您是将页面定向到自身,但是更改了 viewParam 值.

Note the outcome attribute here let's the JSF servlet evaluate the destination url. Basically, an outcome with value of tabs will get rendered as basePath/tabs.xhtml at client side. So basically you are making the page be directed to itself, but changing the viewParam value.

另请参见:

这篇关于来自&lt; p:menuitem&gt;的链接某些&lt; p:tab&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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