2012-05-04 50 views
2

我正在使用帶有``的primefaces 3.1,有四個位置。 在西部位置(西部),我添加了樹形菜單。 JSF代碼如下帶有樹形菜單的Primefaces頁面佈局導航

<p:layoutUnit position="west" size="200" header="Left" 
      resizable="true" collapsible="true"> 
      <h:form> 
       <p:tree dynamic="true" value="#{treeBean.root}" var="node" id="tree" 
        selectionMode="single"> 
        <p:treeNode id="treeNode"> 
         <h:outputText value="#{node}" id="lblNode" /> 
        </p:treeNode> 
       </p:tree> 
      </h:form> 
     </p:layoutUnit> 

,並在TreeBean我

root = new DefaultTreeNode("Root", null); 
     TreeNode node0 = new DefaultTreeNode("Color", root); 


     TreeNode node00 = new DefaultTreeNode("Red", node0); 
     TreeNode node01 = new DefaultTreeNode("Blue", node0); 
     TreeNode node02 = new DefaultTreeNode("Green", node0); 

是它有可能的導航,當我展開,並單擊其中的一個節點,並在點擊相應的節點我怎麼能顯示JSF頁面在佈局的中心位置。即如果我點擊了節點Blue,理想情況下我想將另一個jsf頁面加載到佈局的中心位置。

任何幫助是非常可觀的。

感謝

更新1

我加入以下代碼,它並導航到start.xhtml。但是,start.xhtml不顯示在我的佈局中,start.xhtml顯示爲新頁面。

public void onNodeSelect(NodeSelectEvent event) { 

     try { 
      System.out.println(" here " + event.getTreeNode().getData()); 
      FacesContext 
        .getCurrentInstance() 
        .getApplication() 
        .getNavigationHandler() 
        .handleNavigation(FacesContext.getCurrentInstance(), 
          "null", "/start.xhtml?faces-redirect=true"); 
     } catch (Exception e) { 
      logger.info("error "+e.getMessage()); 
      // TODO: handle exception 
     } 

回答

1

我認爲,你Include one xhtml inside another JSF

它描述瞭如何這個職位將是非常有用的你創建一個模板,然後在你的template client中使用它。 @rags已經告訴過你,但你並不需要使用<p:layout>。上面鏈接的文章更精確。我相信你會在那裏找到你需要的。問候

2

這是在佈局的幫助下實現的。爲您的應用程序定義佈局模板。樣本顯示在這裏...

myLayoutTemplate.xhtml

 <p:layout> 
     <p:layoutUnit position="east" header="Menu" collapsed="true" scrollable="true" collapsible="true" > 
      <ui:insert name="appMenu"> 
       Place Your menu here ... 
      </ui:insert> 
     </p:layoutUnit> 

     <p:layoutUnit position="center" scrollable="true"> 
      <ui:insert name="pageContent"> 
       Page Content is loaded here ..... 
      </ui:insert> 
     </p:layoutUnit> 
    </p:layout> 

在你Page.xhtml這是對你的菜單項的點擊加載,.....

<ui:composition template="myLayoutTemplate.xhtml"> 
    <ui:define name="pageContent"> 

    </ui:define> 
</ui:composition> 
+0

是否有任何其他方式來實現這一目標? – user75ponic

+0

感謝您的幫助,我會嘗試一下。 – user75ponic