简体   繁体   中英

Parameter values concatenated into dynamic columns in Primefaces?

I'm generating is so dynamic columns in a datatable in JSF with Primefaces 4. It turns out that the only way to generate it through two lists where one has data grid and other attributes of the bean. So far it has happened only handle this.

<p:dataTable id="listCust" var="cust" value="#{mantClienteMB.customers}" rows="5"
     rowIndexVar="rowIndex" paginatorPosition="top" resizableColumns="true" emptyMessage="">

    <p:column headerText="N°" width="auto">
        <h:outputText value="#{rowIndex+1}" />
    </p:column>
    <c:forEach items="#{mantClienteMB.columnCustomer}" var="colum">
        <p:column headerText="#{colum.descripcion}" width="auto">
            <ui:fragment rendered="#{colum.entidadBean == 'code'}">
                <h:outputText value="#{cust.code}" />
            </ui:fragment>
            <ui:fragment rendered="#{colum.entidadBean == 'name'}">
                <h:outputText value="#{cust.name}" />
            </ui:fragment>
            <ui:fragment rendered="#{colum.entidadBean == 'comercialName'}">
                <h:outputText value="#{cust.comercialName}" />
            </ui:fragment>
            <ui:fragment rendered="#{colum.entidadBean == 'isActive'}">
                <h:outputText value="#{cust.isActive}" />
            </ui:fragment>
        </p:column>
    </c:forEach>            
</p:dataTable>

In code java:

private List<BaCustomer> customers;
private List<ValidColumnKey> columnCustomer; 

this.setCustomers(new ArrayList<BaCustomer>());
this.getCustomers().add(new BaCustomer("P0001", "PASSARELA S.A.C.", "PASSARELA", true));
this.getCustomers().add(new BaCustomer("P0002", "DARNOX S.A.C.", "DONOFRIO", true));

this.setColumnCustomer(new ArrayList<ValidColumnKey>());        
this.getColumnCustomer().add(new ValidColumnKey(1, "Codigo", "code"));  
this.getColumnCustomer().add(new ValidColumnKey(2, "Nombre", "name"));  
this.getColumnCustomer().add(new ValidColumnKey(3, "Nombre Comercial", "comercialName"));  
this.getColumnCustomer().add(new ValidColumnKey(4, "Estado", "isActive")); 

But it occurred to me that if I could concatenate the value of the alias in the main list with the names of the attributes bean I get from the second list should work, but the problem of contenacion is that only prints the string, but not the result chain.

<p:dataTable id="listCust" var="cust" value="#{mantClienteMB.customers}" rows="5"
             rowIndexVar="rowIndex" paginatorPosition="top" resizableColumns="true" emptyMessage="">

    <p:column headerText="N°" width="auto">
        <h:outputText value="#{rowIndex+1}" />
    </p:column>
    <c:forEach items="#{mantClienteMB.columnCustomer}" var="colum">
        <p:column headerText="#{colum.descripcion}" width="auto">
            <ui:param name="myVar" value="cust.#{colum.entidadBean}" />             
            <h:outputText value="#{myVar}" />                   
        </p:column>
    </c:forEach>            
</p:dataTable>

Anyone have an idea how to print the string value and not just the string as description. Image: http://s2.subirimagenes.com/otros/previo/thump_8745153listcustomers.jpg

Just use bracket-writing

#{cust[colum.entidadBean]}

Hope it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM