0

Is it possible to have different types of components in a single column in a data table using JSF 2.0?

My requirement is that based on the label column value, the value column will have an input text or select list accordingly.

Currently I'm trying to do this via a backing bean. I have the label, value and type of component (e.g. "selectlist") in an arraylist.

When I'm iterating this list in a data table, how do I check the type and depending on the outcome create either an input or select list?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Rekha
  • 1

1 Answers1

3

Use the rendered attribute with a test that uses whatever it is you use to distinguish between an input and a select list.

E.g.

<h:dataTable value="#{yourBacking.yourList} var="item">
    <h:column>
        <h:inputText value="#{item.value}" rendered="#{item.type == 'input'}" />
        <h:selectOneMenu value="#{item.value}" rendered="#{item.type == 'selectlist'}">
            <f:selectItems value="#{item.values}" />
        </h:selectOneMenu>
    </h:column>
</h:dataTable>
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140