I have a modal dialog, where a user can select and deselect roles based on another user and then submit this to the database to be updated.
However, after debugging, the ArrayList
that backs the ManyCheckbox
doesn't get updated, and the selectedRoles
ArrayList
remains to what it originally was.
For example:
I load the application
There is one user in the database with role 'admin'
I try to edit this user and the dialog opens up, 'admin' checkbox is selected.
I click the 'user' role checkbox and click submit
The selectedRoles array is still only just 'admin' instead of 'admin' and 'user'
Here is my dialog modal:
<p:dialog header="Editing User ID: #{usersView.viewUser}" id="editUserDialog" widgetVar="editUserDialog" modal="true" appendTo="@(body)">
<h:form id="editUserForm">
<p:selectManyCheckbox id="roleSelect" value="#{usersView.selectedRoles}" layout="grid" columns="3">
<f:selectItems value="#{rolesView.roles}" var="role" itemLabel="#{role.name}" itemValue="#{role.name}" />
</p:selectManyCheckbox>
<p:separator />
<p:commandButton process="@this" update=":form:tabs:adminView:userTable:userRoleOutput" value="Submit" id="EditUserSubmitButton" actionListener="#{usersView.editUserRole}" oncomplete="PF('editUserDialog').hide();" />
</h:form>
</p:dialog>
UserView:
@ManagedBean(name="usersView", eager=true)
@ApplicationScoped
private ArrayList<String> selectedRoles;
public Arraylist<String> getSelectedRoles()
{
return this.selectedRoles;
}
public void setSelectedRoles(ArrayList<String> roles)
{
this.selectedRoles = roles;
}
public void editUserRole(ActionEvent actionEvent)
{
// This method literally just loops through all users and matches the one we're looking at
User user = findUser();
if (user != null)
{
// gives user checked roles in database and local session
addSelectedRoles(user);
ArrayList<String> rolesToRemove = user.getRoleNames();
rolesToRemove.removeAll(selectedRoles);
// removes user unchecked roles in database and local session
removeSelectedRoles(user, rolesToRemove);
}
else
{
// Handle exception...
}
}
I am working on a restricted VM, so I cannot copy and paste and this is all the information I can post, which I believe is enough.
Any help is greatly appreciated.
I solved my issue by removing process="@this"
and now the ArrayList is getting updated.
process="@this"
means that the current component of the commandLink and hence why it wasn't updating.