Primefaces TabMenu选择不会改变

时间:2014-09-23 07:29:32

标签: jsf jsf-2 primefaces

我尝试为网页构建一个主要的TabMenu。 显示它将指向我想要的页面,但它不会设置activeIndex,因此它仍然看起来仍然在我的主页上。

继承JSF-View(它是一个插入页面的组件):

<ui:component>
<div id="navigation">
    <h:form id="navForm">
        <p:tabMenu activeIndex="#{projectCockpit.pageId}">
            <p:menuitem value="Home" url="/mainPage.xhtml"
                actionListener="#{projectCockpit.setPageId(0)}">
            </p:menuitem>
            <p:menuitem value="Projekte" url="/projects.xhtml">
                <f:setPropertyActionListener value="1"
                    target="#{projectCockpit.pageId}" />
            </p:menuitem>
        </p:tabMenu>
    </h:form>
</div>
</ui:component>

这是我的豆子:

@ManagedBean(name = "projectCockpit")
@SessionScoped
public class projectCockpitBean implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 8049539654282700741L;

private int pageId;

@PostConstruct
protected void init(){
    pageId = 0;
}

public int getPageId() {
    return pageId;
}

public void setPageId(int pageId) {
    this.pageId = pageId;
}

}

1 个答案:

答案 0 :(得分:0)

对于带tabMenu的重定向页面,您必须在两个页面中使用相同的代码。

mainPage.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/template.xhtml">

    <ui:define name="content">
        <p:tabMenu activeIndex="#{param.i}">
            <p:menuitem value="Overview" outcome="/mainPage.xhtml" icon="ui-icon-star">
                <f:param name="i" value="0" />
            </p:menuitem>
            <p:menuitem value="Demos" outcome="/projects.xhtml" icon="ui-icon-search">
                <f:param name="i" value="1" />
            </p:menuitem>
        </p:tabMenu>
        //place your mainPage code here
        <p:outputLabel value="mainPage code"/>
    </ui:define>

</ui:composition>

projects.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/template.xhtml">

    <ui:define name="content">
        <p:tabMenu activeIndex="#{param.i}">
            <p:menuitem value="Overview" outcome="/mainPage.xhtml" icon="ui-icon-star">
                <f:param name="i" value="0" />
            </p:menuitem>
            <p:menuitem value="Demos" outcome="/projects.xhtml" icon="ui-icon-search">
                <f:param name="i" value="1" />
            </p:menuitem>
        </p:tabMenu>
        //place your projects code here
        <p:outputLabel value="projects code"/>
    </ui:define>

</ui:composition>