Re: How to deal with JPA Entities in a Wicket Model? (Data handling in models)
Hi, This can be solved by using a generic LoadableDetachableModel implementation that loads a model via an interface that constructs a new entity. Preferably it is a subclass of a persisting LoadableDetachableModel that has access to EntityManager. The new POJO entity can be stored in the session at low cost without effort. Once entity is persisted, the LDM changes its behavior into that of the super class, and the model object (POJO) is removed from the session. Now its primary key that is used to get it back from EntityManager is stored in the session as usual. The Wicket LDM concept is very powerful. Kind Regards, Bernard On Sat, 04 May 2013 15:35:37 +0200, you wrote: > >Am 03.05.2013 16:28, schrieb Bertrand Guay-Paquet: >>> Best solution I can imagine would be if there would be a callback or >>> overridable method which is called when the user navigates to a page >>> and another one which is called when the user leaves a page. Those >>> methods would be great to prepare and cleanup models. Are there such >>> methods? >> No method will reliably inform you that a user left a page. His WIFI >> could die, the power could go out, etc. You must clear all expired >> temporary data after some time. If your data is stored in the session, >> that's done automatically for you. > >Thanks for your answer. > >I understand, that there can be situations when a user actually doesn't >leave a page the usual way, but if there were a method as described, it >could at least be helpful for all the preceding page-leave-events under >normal conditions. > >At the moment I think I could handle the problem of unsaved data by >using a Stateful Session Bean. > >Best Regards, > >Christian > > > >Mit freundlichen Grüßen, /// Kind Regards, > Christian Reiter - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to deal with JPA Entities in a Wicket Model? (Data handling in models)
I understand, that there can be situations when a user actually doesn't leave a page the usual way, but if there were a method as described, it could at least be helpful for all the preceding page-leave-events under normal conditions. I never use it, but there's javascript's onbeforeunload event. Have a look at http://stackoverflow.com/questions/1704533/intercept-page-exit-event You can add it to a page like so: add(new AjaxEventBehavior("beforeunload") { @Override protected void onEvent(AjaxRequestTarget target) { // Clear data } }); - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to deal with JPA Entities in a Wicket Model? (Data handling in models)
Am 03.05.2013 16:28, schrieb Bertrand Guay-Paquet: Best solution I can imagine would be if there would be a callback or overridable method which is called when the user navigates to a page and another one which is called when the user leaves a page. Those methods would be great to prepare and cleanup models. Are there such methods? No method will reliably inform you that a user left a page. His WIFI could die, the power could go out, etc. You must clear all expired temporary data after some time. If your data is stored in the session, that's done automatically for you. Thanks for your answer. I understand, that there can be situations when a user actually doesn't leave a page the usual way, but if there were a method as described, it could at least be helpful for all the preceding page-leave-events under normal conditions. At the moment I think I could handle the problem of unsaved data by using a Stateful Session Bean. Best Regards, Christian Mit freundlichen Grüßen, /// Kind Regards, Christian Reiter -- Christian Reiter||| c.rei...@gmx.net - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to deal with JPA Entities in a Wicket Model? (Data handling in models)
Hi, On 03/05/2013 9:58 AM, Christian Reiter wrote: Hi! I'm wondering what's the recommended way to store a unpersisted object while it is edited (I'm using EJBs with JPA as backend). Let's imagine I want to build a customer editor which should be able to handle editing of new (unpersisted) and existing (persisted) customers. If I use a loadable detachable model to load the customer from the backed, all unpersisted changes between requests are lost - not really desirable. If I use a simple model which stores the entity in serialized form my sessions are growing and in addition I've to handle entity refreshing if a user navigates back to the page by using the browser's back button to prevent the user from saving an old entity state. I don't use JPA anymore, so this is from memory. If you store the JPA entity objects directly, you're actually storing the proxy objects created by your JPA provider to handle lazy-loading and such. This means you're probably serializing the entity manager as well! That would explain your session size issue. You can use dto (data transfer objects) instead which will not take much room in the session. This means you'll have to transfer data between the dto and the entity. One way or another you must store the edited values between requests if the client doesn't send them back as part of a form. If using dto still makes your session size too large, you can store the temporary data in the database and keep an id pointing to that data in the session. Best solution I can imagine would be if there would be a callback or overridable method which is called when the user navigates to a page and another one which is called when the user leaves a page. Those methods would be great to prepare and cleanup models. Are there such methods? No method will reliably inform you that a user left a page. His WIFI could die, the power could go out, etc. You must clear all expired temporary data after some time. If your data is stored in the session, that's done automatically for you. I hope this helps. Bertrand - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
How to deal with JPA Entities in a Wicket Model? (Data handling in models)
Hi! I'm wondering what's the recommended way to store a unpersisted object while it is edited (I'm using EJBs with JPA as backend). Let's imagine I want to build a customer editor which should be able to handle editing of new (unpersisted) and existing (persisted) customers. If I use a loadable detachable model to load the customer from the backed, all unpersisted changes between requests are lost - not really desirable. If I use a simple model which stores the entity in serialized form my sessions are growing and in addition I've to handle entity refreshing if a user navigates back to the page by using the browser's back button to prevent the user from saving an old entity state. Best solution I can imagine would be if there would be a callback or overridable method which is called when the user navigates to a page and another one which is called when the user leaves a page. Those methods would be great to prepare and cleanup models. Are there such methods? Is there any recommended way to store entities in wicket while they are edited? Kind Regards, Christian Reiter -- Christian Reiter||| c.rei...@gmx.net - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org