You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Rick Curtis <cu...@gmail.com> on 2012/09/04 21:35:27 UTC

Re: DelagatingResultList

Do you have any idea why javax.faces is trying to create an instance
of DelegatingResultList?
Maybe someone from one of the other mailing lists can help us out?

[1]  javax.faces.component.UIComponentBase.restoreAttachedState(
UIComponentBase.java:1842)

On Thu, Aug 30, 2012 at 10:32 AM, José Luis Cetina <ma...@gmail.com>wrote:

> Hi. I have a problem using myfaces 2.1.8 + openjpa 2.2.0 + primefaces
> 3.4-SNAPSHOT.
>
> I dont know if asked this in myfaces list or here, anyway, i hope somebody
> can help me.
>
> I have 2 SelectOneMenu in a composite component(cc), this cc has a
> componentType in a facescomponent class.
>
> The first selectonemenu have a change event in the cc, when this event is
> fired the second selectonemenu load data from the database.
>
> In the facescomponent class i use statehelper to save the state of the 2
> selectonemenu's, but i have a problem:
>
> This is the scenario:
>
> I have this in my database:
>
> Table country:
> id name
> 1  Spain
> 2  Mexico
> 3  USA
>
> Table cities:
> id fk name
> 1  3  New York
> 2  3  LA
>
> When my page load the country selectonemenu show all the countries without
> problem (i retrive them using openjpa),  in the cities selectonemenu's show
> nothing because Spain doesnt have cities, well then if i select Mexico my
> valuechangelistener method execute and load all the cities, but Mexico
> doesnt have nothing in the database then again nothing showed  as expected,
> then if a select USA the cities are retrived OK and they are shown in the
> cities selectonemenu although if i select another city like Spain i can see
> this error (my valuechangelistener never get called again):
>
> java.lang.InstantiationException:
> org.apache.openjpa.kernel.DelegatingResultList
> java.lang.InstantiationException:
> org.apache.openjpa.kernel.DelegatingResultList  at
> java.lang.Class.newInstance0(Class.java:357)    at
> java.lang.Class.newInstance(Class.java:325)     at
> javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1842)
>   at
> javax.faces.component._DeltaStateHelper.restoreState(_DeltaStateHelper.java:616)
>        at
> javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:2021)
>   at
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:661)
>    at
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
>    at
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
>    at
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
>    at
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreView(DefaultFaceletsStateManagementStrategy.java:330)
>    at
> org.apache.myfaces.application.StateManagerImpl.restoreView(StateManagerImpl.java:130)
>  at
> org.apache.myfaces.shared.view.ViewDeclarationLanguageBase.restoreView(ViewDeclarationLanguageBase.java:106)
>    at
> org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.restoreView(FaceletViewDeclarationLanguage.java:2109)
>   at
> org.apache.myfaces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:300)
>    at
> com.ocpsoft.pretty.faces.application.PrettyViewHandler.restoreView(PrettyViewHandler.java:109)
>  at
> org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.WindowContextAwareViewHandler.restoreView(WindowContextAwareViewHandler.java:122)
> at
> org.apache.myfaces.extensions.cdi.jsf.impl.CodiViewHandler.restoreView(CodiViewHandler.java:99)
> at
> javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:83)
>      at
> javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:83)
>      at
> org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:127)
>  at
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
> at
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
>      at
> org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95)
>   at
> javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)  at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
>       at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>       at
> com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
>       at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>       at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
>     at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>     at
> org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)     at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>  at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
>   at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
>    at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
>       at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>       at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>     at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
>     at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
>        at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at
> java.lang.Thread.run(Thread.java:722)
>
>
> I observe this:
>
> If you select countries that doesnt have cities no error is shown
> (something like moving from Spain to Mexico and viceversa), but when i
> select a country like USA that have cities the cities load ok, but if i try
> to select another country like mexico then the valuechangelistener method
> never get called again because the exception is thrown.
>
> I get the cities using this method:
>
> public List<City> getCities(Country country) {
>
>      CriteriaBuilder cb = em.getCriteriaBuilder();
>      CriteriaQuery<City> cq = cb.createQuery(City.class);
>      Root<City> root = cq.from(City.class);
>      cq.select(root);
>      cq.where(cb.equal(root.get(City_.countryId).get(Country_.countryId),
> country.getCountryId()));
>      List<City> resultList = (List<City>)
> em.createQuery(cq).getResultList();
>      return resultList;
> }
>
> I debug my example and i can see in the saveAttachedState method of
> UIComponentBase.java the list of cities is a type of DelagatingResultList
> but i dont understand why, if im doing a cast when i use the getResultList
> method, why openjpa encapsulate my object in a DelagatingResultList?
>
> Then the  attachedObject from the saveAttachedState method arrives as
> DelagatingResultList and then it cant create an instance.
>
> What i did is return a manual arraylist something like this, and the
> exception never thrown.
>
> public List<City> getCities(Country country) {
>     ArrayList<City> list = new ArrayList<City>(2);
>     list.add(new City("New York"));
>     list.add(new City("LA"));
>     return list;
> }
>
> Finally i dont know what or which is wrong, openjpa or myfaces, openjpa
> return a DelagatingResultList object and myfaces cant create an instance of
> that object.
> What can i do ?
>
>
>
>
>
> --
> -------------------------------------------------------------------
> *SCJA. José Luis Cetina*
> -------------------------------------------------------------------
>



-- 
*Rick Curtis*

Re: DelagatingResultList

Posted by José Luis Cetina <ma...@gmail.com>.
I dont have an idea why.

I did a workaround creating an arraylist with the content of getresultlist.
Like this:

List<City> resultList = (List<City>) em.createQuery(cq).getResultList();

//solution
List<City> mySecondList = new ArrayList<City>(resultList);

return mySecondList;
El 04/09/2012 14:35, "Rick Curtis" <cu...@gmail.com> escribió:

> Do you have any idea why javax.faces is trying to create an instance
> of DelegatingResultList?
> Maybe someone from one of the other mailing lists can help us out?
>
> [1]  javax.faces.component.UIComponentBase.restoreAttachedState(
> UIComponentBase.java:1842)
>
> On Thu, Aug 30, 2012 at 10:32 AM, José Luis Cetina <maxtorzito@gmail.com
> >wrote:
>
> > Hi. I have a problem using myfaces 2.1.8 + openjpa 2.2.0 + primefaces
> > 3.4-SNAPSHOT.
> >
> > I dont know if asked this in myfaces list or here, anyway, i hope
> somebody
> > can help me.
> >
> > I have 2 SelectOneMenu in a composite component(cc), this cc has a
> > componentType in a facescomponent class.
> >
> > The first selectonemenu have a change event in the cc, when this event is
> > fired the second selectonemenu load data from the database.
> >
> > In the facescomponent class i use statehelper to save the state of the 2
> > selectonemenu's, but i have a problem:
> >
> > This is the scenario:
> >
> > I have this in my database:
> >
> > Table country:
> > id name
> > 1  Spain
> > 2  Mexico
> > 3  USA
> >
> > Table cities:
> > id fk name
> > 1  3  New York
> > 2  3  LA
> >
> > When my page load the country selectonemenu show all the countries
> without
> > problem (i retrive them using openjpa),  in the cities selectonemenu's
> show
> > nothing because Spain doesnt have cities, well then if i select Mexico my
> > valuechangelistener method execute and load all the cities, but Mexico
> > doesnt have nothing in the database then again nothing showed  as
> expected,
> > then if a select USA the cities are retrived OK and they are shown in the
> > cities selectonemenu although if i select another city like Spain i can
> see
> > this error (my valuechangelistener never get called again):
> >
> > java.lang.InstantiationException:
> > org.apache.openjpa.kernel.DelegatingResultList
> > java.lang.InstantiationException:
> > org.apache.openjpa.kernel.DelegatingResultList  at
> > java.lang.Class.newInstance0(Class.java:357)    at
> > java.lang.Class.newInstance(Class.java:325)     at
> >
> javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1842)
> >   at
> >
> javax.faces.component._DeltaStateHelper.restoreState(_DeltaStateHelper.java:616)
> >        at
> >
> javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:2021)
> >   at
> >
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:661)
> >    at
> >
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
> >    at
> >
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
> >    at
> >
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680)
> >    at
> >
> org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreView(DefaultFaceletsStateManagementStrategy.java:330)
> >    at
> >
> org.apache.myfaces.application.StateManagerImpl.restoreView(StateManagerImpl.java:130)
> >  at
> >
> org.apache.myfaces.shared.view.ViewDeclarationLanguageBase.restoreView(ViewDeclarationLanguageBase.java:106)
> >    at
> >
> org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.restoreView(FaceletViewDeclarationLanguage.java:2109)
> >   at
> >
> org.apache.myfaces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:300)
> >    at
> >
> com.ocpsoft.pretty.faces.application.PrettyViewHandler.restoreView(PrettyViewHandler.java:109)
> >  at
> >
> org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.WindowContextAwareViewHandler.restoreView(WindowContextAwareViewHandler.java:122)
> > at
> >
> org.apache.myfaces.extensions.cdi.jsf.impl.CodiViewHandler.restoreView(CodiViewHandler.java:99)
> > at
> >
> javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:83)
> >      at
> >
> javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:83)
> >      at
> >
> org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:127)
> >  at
> >
> org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
> > at
> >
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
> >      at
> >
> org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95)
> >   at
> > javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)  at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> >       at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> >       at
> > com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> >       at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> >       at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
> >     at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> >     at
> > org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
> at
> >
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> >  at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
> >   at
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
> >    at
> > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
> >       at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> >       at
> >
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> >     at
> >
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
> >     at
> >
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> > at
> >
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
> >        at
> >
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> > at
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> > at
> > java.lang.Thread.run(Thread.java:722)
> >
> >
> > I observe this:
> >
> > If you select countries that doesnt have cities no error is shown
> > (something like moving from Spain to Mexico and viceversa), but when i
> > select a country like USA that have cities the cities load ok, but if i
> try
> > to select another country like mexico then the valuechangelistener method
> > never get called again because the exception is thrown.
> >
> > I get the cities using this method:
> >
> > public List<City> getCities(Country country) {
> >
> >      CriteriaBuilder cb = em.getCriteriaBuilder();
> >      CriteriaQuery<City> cq = cb.createQuery(City.class);
> >      Root<City> root = cq.from(City.class);
> >      cq.select(root);
> >      cq.where(cb.equal(root.get(City_.countryId).get(Country_.countryId),
> > country.getCountryId()));
> >      List<City> resultList = (List<City>)
> > em.createQuery(cq).getResultList();
> >      return resultList;
> > }
> >
> > I debug my example and i can see in the saveAttachedState method of
> > UIComponentBase.java the list of cities is a type of DelagatingResultList
> > but i dont understand why, if im doing a cast when i use the
> getResultList
> > method, why openjpa encapsulate my object in a DelagatingResultList?
> >
> > Then the  attachedObject from the saveAttachedState method arrives as
> > DelagatingResultList and then it cant create an instance.
> >
> > What i did is return a manual arraylist something like this, and the
> > exception never thrown.
> >
> > public List<City> getCities(Country country) {
> >     ArrayList<City> list = new ArrayList<City>(2);
> >     list.add(new City("New York"));
> >     list.add(new City("LA"));
> >     return list;
> > }
> >
> > Finally i dont know what or which is wrong, openjpa or myfaces, openjpa
> > return a DelagatingResultList object and myfaces cant create an instance
> of
> > that object.
> > What can i do ?
> >
> >
> >
> >
> >
> > --
> > -------------------------------------------------------------------
> > *SCJA. José Luis Cetina*
> > -------------------------------------------------------------------
> >
>
>
>
> --
> *Rick Curtis*
>