0
votes

I'm developing an application in JSF 2.0. In the application there has to be a page where users can create document templates. It's comparable to the Google docs form feature. For example users should be able to determine where in the template they want an inputText, a textArea or a selectBooleanCheckbox. I designed a supersclass UiDocumentElement and the subclasses UiTextarea, UiInputText, ... .

Now I was wondering how I could display such a document template on my XHTML page. My backing bean will have a DataModel with UiDocumentElement objects. But how can I use a ui:repeat to display the different types of UI tags? Or should I try another design to achieve this?

Actually it comes to solving this problem:

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

Any help would be greatly appreciated.

EDIT: see BalusC's comment with a link to a related question.

1

1 Answers

1
votes

The easiest would be to have a 3-component block controlled through rendered attribute:

<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'}"/>