checkboxes inside p:datatTable mixed on row deleted

UI Components for JSF
Post Reply
malavock82
Posts: 22
Joined: 15 Aug 2012, 15:50

16 Nov 2015, 18:08

Hi I'm using Spring 4.1.1, JSF 2.2.3 and Primefaces 5.1

I have a dataTable for which, in every row, are present 2 boolean checkboxes to modify a field. The user can modify the entries or remove a whole row.

Code: Select all

<h:form id="editForm">
<p:dataTable id="permissionTable" var="sdp" rowIndexVar="rowIndex" value="${serverDirectoryPermissions}">						
<p:column>
	<f:facet name="header">
		<h:outputText value="name" />
	</f:facet>
	<div>
		<h:outputText value="${sdp.name}"/>
	</div>
</p:column>
<p:column>
	<f:facet name="header">
		<h:outputText value="upload permission" />
	</f:facet>
	<div>
		<p:selectBooleanCheckbox id="canUploadCheck" value="${sdp.hasUploadPermission}" />
	</div>
</p:column>
<p:column>
	<f:facet name="header">
		<h:outputText value="delete permission" />
	</f:facet>
	<div>
		<p:selectBooleanCheckbox id="canDeleteCheck" value="${sdp.hasDeletePermission}" />
	</div>
</p:column>
<p:column>
	<f:facet name="header">
		<h:outputText value="&nbsp;&nbsp;" />
	</f:facet>
	<div>
		<p:commandButton id="removePermission" value="${tmsg.messages.sys_button_remove}" action="${documentManager.removeServerDirectoryPermission(serverDirectoryPermissions,sdp)}" ajax="true" process=":editForm" update=":editForm" immediate="true"/>
	</div>
</p:column>
</p:dataTable>
</h:form>
When clicked the remove button fires an action that removes the selected entry from the original list, and then the ajax call refreshes the form (and so the table)

Code: Select all

	public void removeServerDirectoryPermission(List<ServerDirectoryPermission> sdps, ServerDirectoryPermission sdpToRemove) {
		int index = -1;
		int i = 0;
		for (Iterator<ServerDirectoryPermission> it = sdps.iterator(); it.hasNext(); i++) {
			ServerDirectoryPermission sdp = it.next();
		    if (sdp.getId() == sdpToRemove.getId()) {
		    	index = i;
		    	break;
		    }
		}
		if (index != -1) {
			sdps.remove(index);
		}
	}
When the table refreshes, the correct row is removed. The problem is that all the checkboxes below the deleted row take the value of the row that was directly above them.

e.g.

row1 true false
row2 false true
row3 true true
row4 false false

after I delete row2:

row1 true false
row3 false true
row4 true true

I debugged the back end and the values in the beans for row3 and row4 are not being updated yet, so it's only the GUI that displays the wrong values. Offc ourse if I save the new values are saved.

Am I doing something wrong in the way I delete entries and update the datatable?

For completenes the serverDirectoryPermissions is a list in a flowScope variable and it get persisted in the database when a save button is pressed. The save process works correctly so I omitted the code.

Thanks a lot
Environment: Spring 4.1.1, Spring webflow, JSF 2.2.3, Primefaces 5.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 28 guests