Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 98CCFD3A5 for ; Fri, 31 Aug 2012 13:59:11 +0000 (UTC) Received: (qmail 68111 invoked by uid 500); 31 Aug 2012 13:59:10 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 68051 invoked by uid 500); 31 Aug 2012 13:59:10 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 68040 invoked by uid 99); 31 Aug 2012 13:59:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 13:59:10 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mkienenb@gmail.com designates 209.85.216.181 as permitted sender) Received: from [209.85.216.181] (HELO mail-qc0-f181.google.com) (209.85.216.181) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 13:59:03 +0000 Received: by qcpx40 with SMTP id x40so2228067qcp.12 for ; Fri, 31 Aug 2012 06:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=JkMhAE/3xT/dxeh10/6SgSqi4CUgH3Y5af4ZDxR8qfY=; b=e61ccOwdq4LgIrTaZyOZvxhw2UJGiHU0D4v0PQZip8Br1yf81Mjwn1j7EjW7efcrAx JE/AB7aAUaWk/CVoWRIa8GklgqBdhP859hn4MiryHcWSop5dClS7O58wBRv7O+tSKoSu acRKvJxhkZnN3C7EOGe1/z8XE4H+h+5y8Ayxqpj4NmjNdpyEln2J+u/ewG0hxn6L7hnF fEK0G52mj+vepToPtTtX1FQuV8ueZChVvP4+1BHIMdImHPnQa0fMoB3CoWdKK3bQrJfJ eib0ZRubD/9QDQecluQBv0JfVfhEptBPIatvmrAtFflv8/VvK1b9UHnaOI1LWl5Mk7AB S++Q== Received: by 10.229.135.149 with SMTP id n21mr4917090qct.82.1346421522771; Fri, 31 Aug 2012 06:58:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.230.139 with HTTP; Fri, 31 Aug 2012 06:58:22 -0700 (PDT) In-Reply-To: References: From: Mike Kienenberger Date: Fri, 31 Aug 2012 09:58:22 -0400 Message-ID: Subject: Re: Save component state To: MyFaces Discussion Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org How is the list returned from getCities() being used? Why is the list being serialized in a state? Maybe this below was why and posting the code may help. > In the facescomponent class i use statehelper to save the state of the 2 > selectonemenu's, but i have a problem: One thing to keep in mind is that Myfaces has no control over serializing and instantiating foreign objects. Chances are that you either shouldn't be serializing it in the first place, or you should be converting it to an explictly-serializable form (like a standard list) first. On Thu, Aug 30, 2012 at 11:31 AM, Jos=E9 Luis Cetina = 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 openjpa list or here, anyway, i hope somebod= y > 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 withou= t > problem (i retrive them using openjpa), in the cities selectonemenu's sh= ow > 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 expecte= d, > 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 s= ee > 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(UIComponentBas= e.java:1842) at > javax.faces.component._DeltaStateHelper.restoreState(_DeltaStateHelper.ja= va:616) at > javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:2= 021) at > org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.r= estoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:661) at > org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.r= estoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680) at > org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.r= estoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680) at > org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.r= estoreStateFromMap(DefaultFaceletsStateManagementStrategy.java:680) at > org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.r= estoreView(DefaultFaceletsStateManagementStrategy.java:330) at > org.apache.myfaces.application.StateManagerImpl.restoreView(StateManagerI= mpl.java:130) at > org.apache.myfaces.shared.view.ViewDeclarationLanguageBase.restoreView(Vi= ewDeclarationLanguageBase.java:106) at > org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.restoreVi= ew(FaceletViewDeclarationLanguage.java:2109) at > org.apache.myfaces.application.ViewHandlerImpl.restoreView(ViewHandlerImp= l.java:300) at > com.ocpsoft.pretty.faces.application.PrettyViewHandler.restoreView(Pretty= ViewHandler.java:109) at > org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.WindowConte= xtAwareViewHandler.restoreView(WindowContextAwareViewHandler.java:122) at > org.apache.myfaces.extensions.cdi.jsf.impl.CodiViewHandler.restoreView(Co= diViewHandler.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(RestoreViewExecu= tor.java:127) at > org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.jav= a:170) at > org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117= ) at > org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleW= rapper.execute(CodiLifecycleWrapper.java:95) at > javax.faces.webapp.FacesServlet.service(FacesServlet.java:197) at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicat= ionFilterChain.java:305) at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilte= rChain.java:210) at > com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicat= ionFilterChain.java:243) at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilte= rChain.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) a= t > org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorB= ase.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.j= ava:118) at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:40= 7) at > org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Pr= ocessor.java:1001) at > org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(Abst= ractProtocol.java:579) at > org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.ja= va:312) at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java= :1110) at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.jav= a: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 t= ry > 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 getCities(Country country) { > > CriteriaBuilder cb =3D em.getCriteriaBuilder(); > CriteriaQuery cq =3D cb.createQuery(City.class); > Root root =3D cq.from(City.class); > cq.select(root); > cq.where(cb.equal(root.get(City_.countryId).get(Country_.countryId), > country.getCountryId())); > List resultList =3D (List) > 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 getResultLis= t > 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 getCities(Country country) { > ArrayList list =3D new ArrayList(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 ?