2011-11-29 49 views
0

我正在開發JSF 2.0中的應用程序。 在應用程序中必須有一個頁面,用戶可以創建文檔模板。它與Google文檔表單功能相當。例如用戶應該能夠確定在模板中,他們希望有一個inputText的,一個TEXTAREA或selectBooleanCheckbox。我設計了一個supersclass UiDocumentElement和子類UiTextarea,UiInputText,...。如何在UI中呈現不同的UI標籤:重複

現在我想知道我怎麼能顯示我的XHTML頁面上這樣的文檔模板。我的支持bean將有一個帶有UiDocumentElement對象的DataModel。但是,我如何使用ui:repeat來顯示不同類型的UI標籤?或者我應該嘗試另一種設計來實現這一目標?

實際上涉及到解決這個問題:

<h1>#{backingBean.templateTitle}</h1> 

<ui:repeat value="#{backingBean.uiDocumentElements}" var="uiElement">   
    <label> 
     <span>#{uiElement.label}</span> 
     <!-- here the application should know whether to render an inputText, an inputTextarea or a selectBooleanCheckbox with the attribute value="#{uiElement.value}" --> 
    </label>   
</ui:repeat> 

任何幫助將不勝感激。

編輯:請參閱BalusC的評論與相關問題的鏈接。

+1

相關:http://stackoverflow.com/questions/3510614/how-to-create-dynamic-jsf- 1-2型場/ 3522489#3522489 – BalusC

回答

1

,最簡單的是將有3組分通過塊屬性rendered控制:

<h:inputText value="#{uiElement.value}" rendered="#{uiElement.type == 'input'}"/> 
<h:inputTextarea value="#{uiElement.value}" rendered="#{uiElement.type == 'textArea'}"/> 
<h:selectBooleanCheckbox value="#{uiElement.value}" rendered="#{uiElement.type == 'checkbox'}"/> 
相關問題