I have a Primefaces (5.0) Datatable with dynamic columns as well as dynamic rows. In brief, my problem is how do I set it up so that the cells of the first row are a series of i
Thank you again to Unknown: This is effectively your answer (I don't know if there is a more formal way of attributing it to you, but I am happy to do so ). Much appreciated. xhtml code as follows:
<p:dataTable var="rowMap" rowIndexVar="row" value="#{reviewController.rowMapList}" >
<p:columns value="#{reviewController.columnNameList[0]}" var="columnName" headerText="#{columnName}">
#{rowMap[columnName]}
</p:columns>
<p:columns value="#{reviewController.columnNameList}" columnIndexVar="col" rendered="#{col!=0}" var="columnName" headerText="#{columnName}" >
<f:facet name="header" >#{columnName}</f:facet>
<h:inputTextarea value="#{rowMap[columnName]}" rendered="#{row==0}" />
<h:outputText value="#{rowMap[columnName]}" rendered="#{row!=0}" />
</p:columns>
</p:dataTable>
So it is as you described it for the rows, plus I have added an extra p:columns block just to differentiate the first column, and placed a columnIndexVar with rendered="#{col!=0}" conditional on the main p:Columns block so that the first column does not have the inputTextarea that the other cells of the first row do.
Since you asked you want only the 1st row is editable, I have asked you to use rowIndexVar to manage the rows.
You can use p:dataTable's rowIndexVar attribute.
rowIndexVar is Name of iterator to refer each row index.
Whose iterator name can be used in EL to get the Row Id
For example: if rowIndexVar="row" then you can access each row Index using that iterator name in EL using #{row}.
Example Code:
<p:dataTable rowIndexVar="row" value="..." var="myVar">
<p:column>
<p:inputTextarea rows="2" cols="25" counter="display"
value="#{myVar.myText}" rendered="#{row==0}" id="comment1"
maxlength="200"
counterTemplate="{0} remaining characters"
autoResize="false">
</p:inputTextarea>
<h:outputText value="#{myVar.myText}" rendered="#{row!=0}" />
</p:column>
....
</p:dataTable>