Primefaces – editable dynamic table

jsfjsf-2primefaces

DISCLAIMER – THIS IS NOT DUP OF Is it possible to use p:cellEditor inside a p:columns tag? (read both first)

I am trying to adapt this solution to my context – http://forum.primefaces.org/viewtopic.php?f=3&t=13275

I have a dynamic table like this

Managed Bean

@ManagedBean
@ViewScoped
public class MyMB implements Serializable {

private List<String> columns = new ArrayList<String>();

private List<Map<String,String>> data;

private List<Map<String,String>> filteredData;

private String defaultColumnSort;

public void onCellEdit(CellEditEvent event) {  
    System.out.println(event.getRowIndex());
}  

(...)

and xhtml

            <p:dataTable 
            var="dataRow" 
            value="#{myMB.data}" 
            paginator="true" rows="10"  
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"  
            rowsPerPageTemplate="10,50,100" 
            emptyMessage="No sites found with given criteria" 
            filteredValue="#{myMB.filteredData}"
            editable="true" 
            editMode="cell"
            sortBy="#{myMB.defaultColumnSort}"
            id="rowsTable">              
            <p:ajax event="cellEdit" listener="#{myMB.onCellEdit}"/>
 <ui:remove>
            <p:columns value="#{myMB.columns}" var="column" columnIndexVar="colIndex" sortBy="#{column}" filterBy="#{column}" filterMatchMode="contains">  
                <f:facet name="header">#{column}</f:facet>  
                <p:cellEditor>  
                    <f:facet name="output">
                        <h:outputText value="#{dataRow[column]}" />
                    </f:facet>  
                    <f:facet name="input">
                        <p:inputText id="modelInput" value="#{dataRow[column]}" style="width:96%"/>
                    </f:facet>  
                </p:cellEditor>
            </p:columns>
</ui:remove>

            <c:forEach items="#{myMB.columns}" var="column" varStatus="loop">
                <p:column headerText="#{column}">
                   <p:cellEditor>
                      <f:facet name="output">
                         <h:outputText value="#{dataRow[loop.index].value}" />
                      </f:facet>
                      <f:facet name="input">
                         <p:inputText value="#{dataRow[loop.index].value}"  />
                      </f:facet>
                   </p:cellEditor>     
                </p:column>
             </c:forEach>               

the part between ui:remove works (if I remove the ui:remove tag obviously) and shows me the non-editable table.

I am trying to add the p:cellEditor behavior to these cells, but since it does not work with p:columns, the link above suggests to use c:forEach to unwrap p:columns into several p:column items and, for each one of them, apply p:cellEditor.

The link above also references a dead link – https://stackoverflow.com/questions/10229453/jsf-using-primefaces-datatable-to-implement-a-generic-table-viewer-editor-based 🙁

The problem is: the part outside ui:remove compiles and shows me a table with empty cells, so it sounds like I am messing with the value syntax here for h:outputText value.

What's the proper way to declare the cell content in this case?

I am using primefaces 4.

Best Answer

the problem was in this line

<p:columns value="#{mappingEngineSearchMB.columns}" var="column" columnIndexVar="colIndex" sortBy="#{column}" filterBy="#{column}" filterMatchMode="contains">  

since the table is searchable and can be filtered, these were expected values.

since JSF is so discrete, it just decided not to tell anyone the error was that (JSF is soooooooooo discrete) and decided to just render a lot of empty tables

now the table works fine.

Related Topic