Doug
Doug

Reputation: 390

Dynamically build the column values

I am building a component that will build a data table dynamically. I need to pass in the field name from the class and concatenate it to the var attribute of the table. example : "tblVar.firstName". I have tried this using a ui:param as the below code shows, but it just prints the string expression it doesn't evaluate the firstName.

Is there a way to take a string and turn it into an EL expression.

<composite:interface>
        <composite:attribute name="pageBean" type="pagecode.app.Maintenence" required="true"/>
        <composite:attribute name="dataTableList"/>
        <composite:attribute name="columnHeader"/>
        <composite:attribute name="columnFieldName"/>
</composite:interface>

<composite:implementation>

    <p:dataTable id="doc_code_table" value="#{cc.attrs.pageBean.documentCodeList}" 
            var="tblVar" rowIndexVar="index" paginator="false">

        <ui:param value="#{tblVar}.#{cc.attrs.columnFieldName}" name="colValue"/>

        <p:column headerText="#{cc.attrs.columnHeader}">
            <h:outputText value="#{colValue}"/>
        </p:column>

    </p:dataTable>
</composite:implementation>

Upvotes: 1

Views: 595

Answers (1)

BalusC
BalusC

Reputation: 1108722

You're there indeed creating a string variable. The effect is exactly the same as when you do this:

<h:outputText value="#{tblVar}.#{cc.attrs.columnFieldName}" />

This is not right. You should use the brace notation #{bean[property}} to use a variable as property name. Thus, so:

<h:outputText value="#{tblVar[cc.attrs.columnFieldName]}"/>

See also:

Upvotes: 2

Related Questions