Yes, this method won't work for all cases, but it does help for some. On Tue, Apr 6, 2010 at 12:26 PM, Russell Morrisey <russell.morri...@missionse.com> wrote: > Sorry; what I meant is that the value of the model is stored as a hard > reference. So this will work if your model is a string (person.firstName) but > the OP was concerned with manipulating a list of objects. The concern is if > your model's value is also a persistent object. For example a drop-down, to > select person.manager from a list; or a custom list control to set the value > of person.managerList, if person has 7 bosses (and has to hear about their > mistakes 7 times). The value of "manager" would be stored on the proxy (which > is a potential issue if the value of "manager" is a persistent person object). > > RUSSELL E. MORRISEY > Programmer Analyst Professional > Mission Solutions Engineering, LLC > > | russell.morri...@missionse.com | www.missionse.com > 304 West Route 38, Moorestown, NJ 08057 > > -----Original Message----- > From: James Carman [mailto:jcar...@carmanconsulting.com] > Sent: Monday, April 05, 2010 10:16 PM > To: users@wicket.apache.org > Subject: Re: LoadableDetachable Models > > It doesn't hold onto the persistent object. Here's an example usage: > > IModel<Person> personModel = ...; // Some LDM here! > ProxyModelManager mgr = new ProxyModelManager(); > add(new TextField<String>("firstName", mgr.proxy(new > PropertyModel(personModel, "firstName")))); > > Then, later on in the onSubmit() method, you'd call mgr.commit(). > It's not going to hold onto the object that's loaded from the LDM. It > would hold onto the property values of the object that's loaded from > the LDM, but that's okay. > > On Mon, Apr 5, 2010 at 9:23 PM, Russell Morrisey > <russell.morri...@missionse.com> wrote: >> This approach stores a hard reference to the object. It seems prone to >> causing LazyInitializationExceptions when used with Hibernate. You are >> storing a reference to a persistent object (in this case, the regular Model >> object of the ProxyModel), so if you close your session at the end of the >> request, I would expect you to get this exception on the next request when >> you call a method on a lazy proxy object (ex: >> ((MyObject)model.getObject()).getLazyProperty().getName()). >> >> Do you have some other code to work around it? (like loading a fresh object >> from the session at the beginning of the request) It may be you don't hit >> this problem in your use case. >> >> RUSSELL E. MORRISEY >> Programmer Analyst Professional >> Mission Solutions Engineering, LLC >> >> | russell.morri...@missionse.com | www.missionse.com >> 304 West Route 38, Moorestown, NJ 08057 >> >> >> -----Original Message----- >> From: James Carman [mailto:jcar...@carmanconsulting.com] >> Sent: Monday, April 05, 2010 9:05 PM >> To: users@wicket.apache.org >> Subject: Re: LoadableDetachable Models >> >> You can use what we call a "shadow model" or a "proxy model." >> >> https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/proxy/ProxyModelManager.java >> >> This approach will work for you. Basically, you use the >> ProxyModelManager to "wrap" all of your real models (you have to >> explicitly create models to use this and can't use >> CompoundPropertyModel). Then, when you're done with what you're >> doing, you "commit" your changes into the real models. >> >> On Mon, Apr 5, 2010 at 6:11 PM, Russell Morrisey >> <russell.morri...@missionse.com> wrote: >>> Jeffrey, >>> >>> The problem is that if you use an LDM, the list is loaded from persistent >>> storage, and any non-persisted changes from the previous request are lost. >>> If you don't use an LDM, though, you will have stale objects hanging around >>> from the previous Hibernate session (as you mentioned). >>> >>> Think in the mindset that persistent Hibernate objects are only "valid" >>> within the context of a request. Only transient objects are safe to hold >>> references to. You can implement a custom model which keeps track of >>> transient items between requests. It can extend LDM. >>> >>> For example: >>> -Custom LDM loads the list from persistent storage >>> -User clicks a button to add an object to the list >>> -myCustomModel.addObject(newObject) is called by your ajax behavior >>> (triggered by the click) >>> -The list is modified, and your model internally stores a list of transient >>> objects which were added or removed >>> -On the next request, your implementation of load() can get the persistent >>> list from the database, and modify it according to the un-persisted changes >>> the model knows about (make a copy of the list and add or remove the >>> transient items). >>> >>> If you don't like putting a method like addObject(...) on your model, you >>> could put some logic in your setObject(...) method which sorts out the >>> changes made to the list. You should not hold a reference to a persistent >>> object after detach(). A tool like JProbe or jvisualvm (in JDK6) is great >>> for identifying problem cases. >>> >>> If you have a component who depends on the data from another component with >>> unsaved changes, you can submit data for the "prerequisite" in the same >>> request, so that the information is current. >>> >>> HTH, >>> >>> RUSSELL E. MORRISEY >>> Programmer Analyst Professional >>> Mission Solutions Engineering, LLC >>> >>> | russell.morri...@missionse.com | www.missionse.com >>> 304 West Route 38, Moorestown, NJ 08057 >>> >>> -----Original Message----- >>> From: Jeffrey Schneller [mailto:jeffrey.schnel...@envisa.com] >>> Sent: Monday, April 05, 2010 3:26 PM >>> To: users@wicket.apache.org >>> Subject: LoadableDetachable Models >>> >>> I am having issues with LDM, Hibernate lazy loaded lists, and ajax. >>> >>> >>> >>> I create a CompoundPropertyModel of a LDM and set that as the default >>> model for the page. >>> >>> I then pass the model to the form and to a custom component in the form. >>> The custom component is a list editor. Basically a ListView with lots >>> of ajax link for editing the values. >>> >>> >>> >>> The issue I am having is I can get everything to work however because of >>> the LDM, the model is being over-written on each Ajax request and also >>> on form submission so I cannot modify any values since they are not >>> available in the onsubmit because the LDM reloads. >>> >>> >>> >>> If I do not use the LDM then I get Hibernate errors because of the lazy >>> loading. >>> >>> >>> >>> If I remove the lazy loading and use eager loading and don't use the LDM >>> then everything works fine. The issue is because of the eager loading >>> then other parts of the application load lots of data that is not >>> needed. >>> >>> >>> >>> Any ideas? Can I not use the LDM for what I want? >>> >>> >>> >>> Thanks. >>> >>> >>> >>> >>> This is a PRIVATE message. If you are not the intended recipient, please >>> delete without copying and kindly advise us by e-mail of the mistake in >>> delivery. >>> NOTE: Regardless of content, this e-mail shall not operate to bind MSE to >>> any order or other contract unless pursuant to explicit written agreement >>> or government initiative expressly permitting the use of e-mail for such >>> purpose. >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>> For additional commands, e-mail: users-h...@wicket.apache.org >>> >>> >> >> >> This is a PRIVATE message. If you are not the intended recipient, please >> delete without copying and kindly advise us by e-mail of the mistake in >> delivery. >> NOTE: Regardless of content, this e-mail shall not operate to bind MSE to >> any order or other contract unless pursuant to explicit written agreement or >> government initiative expressly permitting the use of e-mail for such >> purpose. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > > This is a PRIVATE message. If you are not the intended recipient, please > delete without copying and kindly advise us by e-mail of the mistake in > delivery. > NOTE: Regardless of content, this e-mail shall not operate to bind MSE to any > order or other contract unless pursuant to explicit written agreement or > government initiative expressly permitting the use of e-mail for such purpose. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org