Ok I successfully figured out my dymanic column problem. I used Tosh's example to make my own:
Code: Select all
<p:dataTable value="#{ityteacher.gradebook.columnValues}" var="columnValues" id="currentGrades" tableStyle="table-layout:auto" editable="true" editMode="cell" widgetVar="gradeBook" scrollable="true">
<p:ajax event="cellEdit" listener="#{ityteacher.onGradeCellEdit}" />
<c:forEach items="#{ityteacher.gradebook.columnNames}" var="column" varStatus="colLoopStatus">
<p:column headerText="#{column}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{columnValues[colLoopStatus.index]}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{columnValues[colLoopStatus.index]}" />
</f:facet>
</p:cellEditor>
</p:column>
</c:forEach>
</p:dataTable>
The absolute important thing to make this work at all is that the getGradebook() function in this example must only be created once upon construction.
So I needed to do this:
Code: Select all
public GradeBook getGradebook(){
if(gradeBook==null){
........
}
return gradeBook;
}
If you keep regenerating the gradeBook values, the "new" and "old" values will always be 'null'.
Also one peice of trivia, you can get the row of the value changed easily through
Code: Select all
public void onGradeCellEdit(CellEditEvent event) {
int row = event.getRowIndex();
}
But if you want to get the column that changed, you find out through the column header:
Code: Select all
public void onGradeCellEdit(CellEditEvent event) {
String column = event.getColumn().getHeaderText();
}
So when a change is made, you'll have this information:
Old value
New value
Numeric Row indicator
Header string of column
Here is the structure for "Gradebook" as shown above, FYI:
Code: Select all
public class GradeBook {
List<String> columnNames;
List<List<String>> columnValues;
public List<String> getColumnNames() {
return columnNames;
}
public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}
public List<List<String>> getColumnValues() {
return columnValues;
}
public void setColumnValues(List<List<String>> columnValues) {
this.columnValues = columnValues;
}
}
-Derrick