I’m trying to create a datatable with the in cell editor. I have a column called “groups” which shows a list of groups. When the cell editor icon is clicked, it shows a checkboxMenu where a user can check whatever groups they want and then click submit.
I don’t even have my rowEditEvent handler yet and i’m getting a collection unmodifable exception. I can’t figure out what i’m doing wrong that i’m getting this exception.
Any help is appreciated.
group_admin.xhtml
<h:form>
<p:dataTable value="#{userBacking.users}" var="users" editable="true">
<p:column headerText="Groups">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{users.groups}" />
</f:facet>
<f:facet name="input">
<p:selectCheckboxMenu value="#{users.groups}" label="Groups">
<f:selectItems value="#{groupBacking.groupsAsSelectItems}" />
</p:selectCheckboxMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Actions">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
getUsers
public List<UserBean> getUsers() throws Exception {
ContentManager cm = null;
cm = getContentManager();
if(users == null) {
users = new ArrayList<UserBean>();
UserManager um = cm.getUserManager();
List<? extends Group> cmsGroups = um.getCmsDefinedGroups();
List<? extends User> allUsers = um.getAllUsers(0, Integer.MAX_VALUE);
// loop through each user
for(User u : allUsers) {
Set<? extends Group> groups = u.getGroups();
UserBean user = new UserBean();
user.setUserName(u.getUserName());
user.setGroups(groups); // THIS LINE CAUSES THE EXCEPTION
users.add(user);
}
}
return users;
}
UserBean
public class UserBean implements User {
private String userName;
private String firstName;
private String lastName;
private Set<? extends Group> groups = null;
public UserBean() {}
public UserBean(String userName, String firstName, String lastName, Set<? extends Group> groups) {
this.userName = userName;
this.firstName = firstName;
this.lastName = lastName;
this.groups = groups;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Set<? extends Group> getGroups() {
return groups;
}
public void setGroups(Set<? extends Group> groups) {
this.groups = groups;
}
public void removeGroups() {
groups = null;
}
@Override
public boolean isDisabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public UserProfile getProfile() {
// TODO Auto-generated method stub
return null;
}
}
Stacktrace
Oct 9, 2012 1:09:08 PM com.sun.faces.renderkit.html_basic.MenuRenderer createCollection
SEVERE: Unable to create new Collection instance for type java.util.Collections$UnmodifiableSet
java.lang.InstantiationException: java.util.Collections$UnmodifiableSet
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.faces.renderkit.html_basic.MenuRenderer.createCollection(MenuRenderer.java:907)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:367)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:129)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
at org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer.getConvertedValue(SelectCheckboxMenuRenderer.java:34)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1028)
at javax.faces.component.UIInput.validate(UIInput.java:958)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1209)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1086)
at javax.faces.component.UIData.iterate(UIData.java:1501)
at javax.faces.component.UIData.processValidators(UIData.java:1026)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:485)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIData.visitTree(UIData.java:1233)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1518)
at javax.faces.component.UIForm.visitTree(UIForm.java:335)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1518)
at org.primefaces.component.tabview.TabView.visitTree(TabView.java:400)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1518)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1518)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:366)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:246)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1163)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thre
ad.java:662)
The stacktrace suggests that
u.getGroups()returned aCollections#unmodifiableSet(). When JSF needs to process the submitted values from the checkbox group, it is trying to instantiate a collection of the same type, but that type is uninstantiable.Wrapping it in a modifiable set such as
HashSetshould fix the particular problem:Unrelated to the concrete problem, there are more other potential problems in the code posted so far, but they are not related to particular exception which you faced. So, fixing the current problem may cause a different exception, but this would not be related to the current one at all.