0

Listbox selectedItems and Hibernate collection types don't play together?

asked 2012-08-23 06:48:24 +0800

billyboingo gravatar image billyboingo
6

ZK Version: 6.0.2
Hibernate: 4.1.5

I have a User object that I am editing via a form. The user holds a collection of Granted Authorities (Spring Security). These are stored in hibernate in a OneToMany relationship. My VM provides a Collection of all possible Granted Authorities. So my zul looks like this:

...
					<groupbox>
						<caption label="Authorities"></caption>
						<listbox model="@load(vm.authorities)"
							selectedItems="@bind(fx.authorities)"
							multiple="true" checkmark="true" vflex="true" hflex="true">
							<template name="model">
								<listitem>
									<listcell
										label="@load(each.name)">
									</listcell>
									<listcell
										label="@load(each.description)">
									</listcell>
								</listitem>
							</template>
						</listbox>
					</groupbox>
...

The current authorities for the user are properly selected and displayed - right up to the point where you try and change any of the checkboxes. Then you get this:

Aug 22, 2012 11:42:22 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1351
SEVERE: >>org.zkoss.zel.ELException: Cannot convert [] of type class java.util.HashSet to class org.hibernate.collection.internal.PersistentSet
>>	at org.zkoss.zel.impl.lang.ELSupport.coerceToTypeForSetValue(ELSupport.java:468)
>>	at org.zkoss.zel.impl.parser.AstValue.setValue(AstValue.java:244)
>>	at org.zkoss.zel.impl.ValueExpressionImpl.setValue(ValueExpressionImpl.java:256)
>>	at org.zkoss.xel.zel.ELXelExpression.setValue(ELXelExpression.java:50)
>>	at org.zkoss.bind.impl.BindEvaluatorXImpl.setValue(BindEvaluatorXImpl.java:50)
>>	at org.zkoss.bind.impl.SavePropertyBindingImpl.save(SavePropertyBindingImpl.java:128)
>>	at org.zkoss.bind.impl.PropertyBindingHandler.doSaveBinding(PropertyBindingHandler.java:148)
>>	at org.zkoss.bind.impl.PropertyBindingHandler.doSaveEvent(PropertyBindingHandler.java:203)
>>	at org.zkoss.bind.impl.BinderImpl.doSaveEvent(BinderImpl.java:1388)
>>	at org.zkoss.bind.impl.BinderImpl.access$1300(BinderImpl.java:95)
>>	at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1128)
>>	at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1101)
>>	at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2736)
>>	at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2707)
>>	at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2648)
>>	at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
>>	at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1709)
>>	at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1494)
>>	at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1204)
>>	at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:558)
>>	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:456)
>>	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:464)
>>	at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
>>	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
>>	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:594)
>>	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1366)
>>	at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
>>	at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
>>	at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
>>	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
>>	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1337)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
>>	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
>>	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
>>	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
>>	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
>>	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
>>	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
>>	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1337)
>>	at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119)
>>	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>>	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
>>	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
>>	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1337)
>>	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:484)
>>	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
>>	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
>>	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
>>	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
>>	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
>>	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
>>	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
>>	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
>>	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
>>	at org.eclipse.jetty.server.Server.handle(Server.java:351)
>>	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
>>	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:900)
>>	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:954)
>>	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:857)
>>	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
>>	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
>>	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609)
>>	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
>>	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
>>	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
>>	at java.lang.Thread.run(Unknown Source)

Question is: does selectedItems just not work with Hibernate collection types? Is there a clean workaround? Am I missing something?

Thanks!

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-11-15 19:27:17 +0800

ebartley13 gravatar image ebartley13
13 1

I had the same problem, and the best workaround I found is below. It's trying to call the setter for the Collection property and pass in it's own Collection of selected items and is failing to coerce it's Collection to the concreate type. I'd much rather it treated the object as a generic Set and used the methods in Set to add/remove the items, it seems like it'd be safer.

ViewModel

	public void selectSkill(SelectEvent<Listitem, Skill> event) {
	    analyst.getSkills().retainAll(event.getSelectedObjects());
	    analyst.getSkills().addAll(event.getSelectedObjects());
	}

ZUL

	<listbox model="@load(vm.allSkills)" selectedItems="@load(analyst.skills)" checkmark="true" multiple="true"
		id="analystSkillsListBox" onSelect="vm.selectSkill(event)">
		....
	</listbox>

link publish delete flag offensive edit

answered 2013-01-24 16:27:39 +0800

ajaidka gravatar image ajaidka
196 4

I had the same kind of issue, while using list box, and on onSelect event I was populating another list (oneToMany relation) through load form. But as soon as I add new Item in main list, I get this error. Solution was to load complete list again after adding new items in list. Like in your case you can load vm.authorities again.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-08-23 06:48:24 +0800

Seen: 198 times

Last updated: Feb 08 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More