2014-09-23 78 views
1

我嘗試爲Web-Page構建一個primefaces TabMenu。 它顯示它將我指向我想要的頁面,但它不會設置activeIndex,因此它仍然看起來像我仍然在我的主頁上。Primefaces TabMenu選擇不會改變

繼承人的JSF-視圖(這是一個組件,該組件插入到頁面):

<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; 
} 

} 

回答

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> 
+0

我使用相同的代碼。主頁面和項目頁面只是模板的。在這個模板中導航被插入... – FlyingSpaten 2014-09-23 15:18:41