I have the following xhtml:
<h:form>
...
<p:dataTable id="table" value="#{BEAN.rows} var="row" >
<p:ajax event="rowEdit" listener="#{BEAN.rowEdit}" />
<p:ajax event="rowEditInit" listener="#{BEAN.rowEditInit}" />
<p:ajax event="rowEditCancel" listener="#{BEAN.rowEditCancel}" />
...
<p:columns id="columnsElement"
value="#{BEAN.columns} var="column" >
<f:facet name="header" >
<h:outputText value="#{column.code}" />
<p:selectBooleanCheckbox id="selectAll"
disabled="#{BEAN.rowInEdit}" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<p:selectBooleanCheckbox id="cellCheck"
disabled="#{BEAN.rowInEdit} />
</f:facet>
<f:facet name="input">
<p:selectBooleanCheckbox id="selectAll"
disabled="true" />
</f:facet>
</p:cellEditor>
</p:columns>
</p:dataTable> </h:form>
With the RowEdit listeners as follows:
public void rowEditInit(RowEditEvent event) {
rowInEdit = true;
UIData table = (UIData) event.getComponent();
String tableId = table.getClientId();
updateTableCheckboxes(tableId, table.getRowIndex()); }
public void rowEdit(RowEditEvent event) {
rowInEdit = false;
UIData table = (UIData) event.getComponent();
String tableId = table.getClientId();
updateTableCheckboxes(tableId, table.getRowIndex()); } // same for rowEditCancel
public void updateTableCheckboxes(String tableId, int index) {
int rowNumber = 0;
for (RowData row : rows) {
int columnNumber = 0;
for (ColumnData column : columns) {
if (row != index) {
String updateCheckboxId = tableId + ":" + rowNumber
+ ":columnsElement:" + columnNumber + ":cellCheck";
FacesContext.getCurrentInstance()
.getPartialViewContext().getRenderIds()
.add(updateCheckboxId);
}
columnNumber++;
}
rowNumber++;
}
columnNumber = 0;
while (columnNumber < columns.size()) {
String selectAllCheckboxId = tableId + ":columnsElement:"
+ columnNumber + ":selectAll";
FacesContext.getCurrentInstance().getPartialViewContext()
.getRenderIds().add(selectAllCheckboxId);
columnNumber++;
}}
This is dynamically populating the Ids of the check boxes in columnsElement
to be updated and is working fine for rowEditInit
, disabling all checkboxes as expected. When I click the tick/cross for the rowEdit
or rowEditCancel
event the Ids to be updated are populated exactly the same, but only the check boxes of the row which had been edited are re-enabled.
If I click on a component elsewhere on the screen or one of the re-enabled check boxes then check boxes of other rows and the selectAll check boxes are all re-enabled as well strangely.
I have tried debugging the JSF lifecycle phases as in this blog, but all stages of the lifecycle are called exactly the same for Init, Edit and Cancel.
As far as I can see I'm doing the same thing, but getting different results in the different cases. Any suggestions why this could be happening?
Thanks
update="..."
? I haven't used that because there's no way to know how many rows/columns there will be, so I need to add the Ids for update this way... I've based this on the answer to this question stackoverflow.com/questions/20901447/… . Apologies if it's difficult to read, in my actual code there's comments and JavaDocs to hopefully make it better, but for the sake of this question I've tried to make the code a bit more generic and removed these comments to save a bit of space. – hello123