I have the following selectManyCheckbox inside a p:wizard component:
<p:wizard id="wizard">
<p:tab id="page1" >
<h:selectManyCheckbox
value="#{userController.user.roles}"
layout="pageDirection"
converter="securityRoleConverter">
<f:selectItems value="#{userController.rolesSelectMany}" />
</h:selectManyCheckbox>
</p:tab>
<p:tab id="page2">
<p:commandButton
value="Save"
action="#{userController.create}"/>
</p:tab>
</p:wizard>
The roles property is an enum in the User class:
public class User {
public enum SecurityRole {
SENDER,
RECEIVER,
SUBSCRIBER,
ADMIN;
}
String firstName;
private List<SecurityRole> roles;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public List<SecurityRole> getRoles() {
if (roles == null) {
roles = new ArrayList<SecurityRole>();
}
return roles;
}
public void setRoles(List<SecurityRole> roles) {
this.roles = roles;
}
}
The user controller is a JSF managed bean:
@ManagedBean
@ViewScoped
public class UserController {
private User user;
public User getUser() {
return user;
}
public SelectItem[] getRolesSelectMany() {
return JsfUtil.getSelectItems(Arrays.asList(SecurityRole.values()), false);
}
public void create() {
// user is created here
}
@FacesConverter(value = "securityRoleConverter")
public static class SecurityRoleConverter extends EnumConverter {
public SecurityRoleConverter() {
super(SecurityRole.class);
}
}
}
When I go from the first wizard page to the second page, the roles property is correctly set (verified in the debugger). However, when I click on the Save button on the 2nd wizard page, the roles property is set to an empty list (the corresponding setter is called). Other properties such as firstName remain. I noticed that this happens to every type of property, if it used inside a <h:select* />
component such as <h:selectManyCheckBox/>
. This looks like a bug in the wizard component to me. Any ideas?
Thanks, Theo