Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jan Bub
SelectManyCheckbox throws ClassCast Exception
August 15, 2012 1:43 AM
Answer

Jan Bub

Rank: Junior Member

Posts: 78

Join Date: March 2, 2011

Recent Posts

Hey again. While developing a portlet for quizzes I got a problem by using the selectManyCheckbox-Compnent. No matter if i use primeface or the default jsf version.
View
1
2<h:selectManyCheckbox    value="#{quizController.selectedMultipleAnswerIds[question.id]}">
3    <f:selectItems value="#{question.answers}" var="answer" itemLabel="#{answer.answerText}"
4        itemValue="#{answer.id}" />
5</h:selectManyCheckbox>
6<p:commandButton styleClass="redButton" value="Quiz auswerten!"
7                actionListener="#{quizController.evaluateQuiz}"
8                update="frontendForm" />


The selected values should stored in a List which is inside a Map because I want the selected answers for each question of a quiz. When i press the button to get the List-values of the Map in the controller, a ClassCastException is thrown.

ControllerBean
1
2private Map<Integer, List<String>> selectedMultipleAnswerIds;
3...
4for(List<String> list:selectedMultipleAnswerIds.values()) {
5    list.size();
6}



Stacktrace
  1
  22012-08-15 08:23:16,852 ERROR [com.liferay.faces.bridge.context.ExceptionHandlerAjaxImpl] - java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
  3javax.faces.event.AbortProcessingException: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
  4    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
  5    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
  6    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
  7    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
  8    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
  9    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
 10    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
 11    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
 12    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
 13    at com.liferay.faces.bridge.lifecycle.LifecycleWrapper.execute(LifecycleWrapper.java:35)
 14    at com.liferay.faces.bridge.BridgePhaseResourceImpl.execute(BridgePhaseResourceImpl.java:99)
 15    at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:116)
 16    at javax.portlet.faces.GenericFacesPortlet.serveResource(GenericFacesPortlet.java:178)
 17    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
 18    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
 19    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
 20    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 21    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 22    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 23    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
 24    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
 25    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 26    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 27    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
 28    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
 29    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
 30    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
 31    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:531)
 32    at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:626)
 33    at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:436)
 34    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:1075)
 35    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:719)
 36    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
 37    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 38    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 39    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:176)
 40    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 41    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 42    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 43    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:560)
 44    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:537)
 45    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 46    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 47    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 48    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
 49    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 50    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 51    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 52    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 53    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 54    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 55    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
 56    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
 57    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
 58    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
 59    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
 60    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 61    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 62    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
 63    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
 64    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
 65    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
 66    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:138)
 67    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 68    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 69    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 70    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
 71    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 72    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 73    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 74    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 75    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 76    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
 77    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
 78    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
 79    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
 80    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 81    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
 82    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
 83    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
 84    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
 85    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 86    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
 87    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
 88    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
 89    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
 90    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 91    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 92    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
 93    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 94    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:246)
 95    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
 96    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
 97    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
 98    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
 99    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
100    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
101    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
102    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
103    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
104    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
105    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
106    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
107    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
108    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
109    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:216)
110    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
111    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
112    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
113    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
114    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
115    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
116    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
117    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
118    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
119    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
120    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
121    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
122    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
123    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
124    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
125    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
126    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
127    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
128    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
129    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
130    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
131    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
132    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
133    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
134    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
135    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
136    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
137    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
138    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
139    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
140    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
141    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
142    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
143    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
144    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
145    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
146    at java.lang.Thread.run(Thread.java:662)
147Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
148    at de.planetic.customer.d11503.liferay.portlet.quiz_portlet.controller.frontend.QuizController.evaluateQuiz(QuizController.java:156)
149    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
150    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
151    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
152    at java.lang.reflect.Method.invoke(Method.java:597)
153    at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
154    at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
155    at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
156    at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
157    at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
158    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
159    ... 142 more


We have an earlier version of this portlet which runs on Liferay 6.0.6 but with old versions of portletfaces-bridge (2.0.2) and liferayfaces (6.0.0.0). That version is working without throwing the exception. Is it possible that there is an error in the bridge. In both cases the jsf version is the same. (2.1.2)
David H Nebinger
RE: SelectManyCheckbox throws ClassCast Exception
August 15, 2012 5:03 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7157

Join Date: September 1, 2006

Recent Posts

Jan Bub:
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List


This would seem to indicate that you do not have a List, you have a String[].
Jan Bub
RE: SelectManyCheckbox throws ClassCast Exception
August 15, 2012 5:41 AM
Answer

Jan Bub

Rank: Junior Member

Posts: 78

Join Date: March 2, 2011

Recent Posts

Hey, thanks for the quick answer.

Thats right, but it should be a list. If i use the List not from a map it works fine.
Like in this example working with list is no problem. But because I have a large number of questions which each have some answers I put the slectedAnswerList into a map. The fails when try to get the value from it after processing.

In addition to that the code worked fine in the older version. I will test it now with old proltetbridge again, wich can be no solution because of the improvemnts of liferay faces that we really need.
Neil Griffin
RE: SelectManyCheckbox throws ClassCast Exception
August 15, 2012 6:59 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2145

Join Date: July 26, 2005

Recent Posts

The example link you mentioned points to p:selectManyCheckBox but your code uses the stock JSF h:selectManyCheckBox component tag. The java.util.List coercion might be a unique feature of PrimeFaces?
Jan Bub
RE: SelectManyCheckbox throws ClassCast Exception
August 22, 2012 12:06 AM
Answer

Jan Bub

Rank: Junior Member

Posts: 78

Join Date: March 2, 2011

Recent Posts

No, it does not working with <p:selectManyCheckBox> too. I just changed to the h: tag because I wanted to see if this could work. But no chance.

The good news is taht it works now if I use the Array[] instead of List. Thats not so flexible but seems to work.
Christian Reitz
RE: SelectManyCheckbox throws ClassCast Exception
August 22, 2012 1:27 PM
Answer

Christian Reitz

Rank: New Member

Posts: 4

Join Date: May 10, 2012

Recent Posts

Jan Bub:
The good news is taht it works now if I use the Array[] instead of List. Thats not so flexible but seems to work.


Maybe a good flexible and easy way converting array <> list ... emoticon:

 1  // prepare list
 2  List<String> _list = new ArrayList<String>();
 3  _list.add("a");
 4  _list.add("b");
 5
 6  // convert list to array (dynamic way)
 7  String[] _array = (String[]) _list.toArray(new String[0]);
 8       
 9  // re-convert array to list (dynamic way)
10  _list = java.util.Arrays.asList(_array);