Andrew Churchill
Andrew Churchill

Reputation: 11

How to dynamically Access `c:set` defined values in JSF Facelets (Primefaces Datatable)?

The value defined by c:set refers to a var (name of the iterator variable used to refer each data), but the column values are not displayed.

How should it be defined to be displayed correctly?

<c:set var="column1_label" value="Id" scope="view" />
<c:set var="column1_value" value="#{data.id}" scope="view" />
<c:set var="column2_label" value="Code" scope="view" />
<c:set var="column2_value" value="#{data.code}" scope="view" />
<c:set var="column3_label" value="Name" scope="view" />
<c:set var="column3_value" value="#{data.name}" scope="view" />

<p:dataTable id="dataTableId" value="#{testView.products}" var="data">
    <c:forEach begin="1" end="3" var="idx">
        <p:column headerText="#{viewScope['column' += idx += '_label']}">
            <h:outputText value="#{viewScope['column' += idx += '_value']}" />
        </p:column>
    </c:forEach>
</p:dataTable>

we have some hundred different views which contain one or more datatables. therefore we build a template containing the datatable which we include on different sites. to keept it simple we want to define the columns of datatable which should hold also the values. not to have to define each column separate in that template we would prefer to have a loop for all that columns (see sample above), because of complex stuff which column can have (different format, different inputfields, converter, editmode, colors,.... which should be configured with c:set in all that views). Problem is that it seems to be impossible to get the value because ui:param is not suitable and c:set also doesn't work with name of iterator variable name.

Upvotes: 0

Views: 38

Answers (0)

Related Questions