Com.sun.faces.renderkit.html_basic.MenuRenderer createCollection: cannot create a new Collection instance for type java.util.Arrays $ ArrayList

I am trying to use the JSF / SelectManyCheckBox tag with the enumeration:

Here is my xhtml code:

<h:form id="searchForm"> <h:panelGrid columns="2"> <h:outputText value="Searched queues" /> <h:panelGroup> <h:selectManyCheckbox layout="pageDirection" value="#{jmsErrorController.errorSearchCriteria.searchedQueues}" converter="queueConverter"> <f:selectItems value="#{jmsErrorController.completeQueueList}" /> </h:selectManyCheckbox> </h:panelGroup> </h:panelGrid> <h:commandButton action="#{jmsErrorController.search}" value="Search !" /> </h:form> 

I added the converter as indicated in another post.

Everything seems to be fine, but I see this stack trace on the console:

 28-Jun-2013 09:07:46 com.sun.faces.renderkit.html_basic.MenuRenderer createCollection SEVERE: Unable to create new Collection instance for type java.util.Arrays$ArrayList java.lang.InstantiationException: java.util.Arrays$ArrayList 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 javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) 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:593) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) 

After that, the stacktrace application seems to work fine, but I wonder why such a stacktrace exists.

Can someone help me?

Thanks.

Stéphane.

+7
source share
1 answer

This will happen when the value component provided by UISelectMany is created using Arrays#asList() instead of new ArrayList() .

If the value model is already pre-populated, JSF will try to use the exact same type to enter the presented values ​​and set a new model value. However, the java.util.Arrays$ArrayList type returned by Arrays#asList() is internal to the java.util.Arrays class, and not individually, as in new Arrays$ArrayList() . Hence this exception.

To fix this, make sure the value is created using new ArrayList() .

Alternatively, explicitly specify the type of the collection using the collectionType attribute, as indicated in this close answer: org.hibernate.LazyInitializationException in com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel .

 <h:selectManyCheckbox ... collectionType="java.util.ArrayList"> 
+14
source

All Articles