2011-12-15 98 views
1

我在我的jsf應用程序中使用facelets進行模板。我想在UI中有條件地包含一個模板文件:composition標籤。如果用戶登錄,則模板必須爲「authorized.xhtml」,如果用戶未登錄,則該模板必須爲「unauthorized.xhtml」。有沒有辦法做到這一點?謝謝。有條件地在ui中包含模板文件:composition標籤

<ui:composition template="/templates/unauthorized.xhtml"> 
<ui:composition template="/templates/authorized.xhtml"> 

我正在使用JSF 1.2。

+0

我現在從支持bean中的方法中檢索模板值,我在此檢查用戶是否已登錄。如果用戶登錄,則返回「/templates/authorized.xhtml」,否則返回「/templates/unauthorized.xhtml」。我無法發佈此信息作爲答案,因爲我沒有100個信譽點。 – 2011-12-15 11:46:26

回答

6

我會嘗試isAuthorized()屬性三元操作,如果你有一個在你登錄豆:

<ui:composition template="#{loginbean.authorized ? '/templates/authorized.xhtml' : '/templates/unauthorized.xhtml'}"> 

或者使用兩個<h:panelGroup>標籤適當rendered值:

<h:panelGroup rendered="#{loginbean.authorized}"> 
    <ui:decorate template="/templates/authorized.xhtml"> 
</h:panelGroup> 

<h:panelGroup rendered="#{not loginbean.authorized}"> 
    <ui:decorate template="/templates/unauthorized.xhtml"> 
</h:panelGroup> 
+1

面板組方法將不起作用,``應該是根標籤,但EL方法可以正常工作 – BalusC 2011-12-15 14:20:28