Hi All, Follow-up to my own post. I found the following here: http://old.nabble.com/Wicket---No-Serializable-objects-Web-application-t d19351608.html
Quote: "However , there is a problem if you use loadabledetachable with AJAX requests on your page. Model.detach() is called on every request, which causes your object to be retrieved from database on the next Model.getObject() call. This means you lose all changes on your bound domain obect on every ajax request. I found to solutions to this, and i like neither of them: a) use DTOs, which means a lot of code duplication. b) write the current object state to the database on every detach, which means you might store objects in an incomplete state, before the user explicitly tells the application to store what she or hehas entered. If anybody has a nicer solution to this, i'd love to hear about it. " Option b) is definitely a no-go, so it seems I'll have to use DTO's then. If someone knows of a nicer solution I would also love to hear about it. For now I guess I'll go the DTO road. Thanks, Jonck -----Original Message----- From: Kogel, Jonck-van-der [mailto:[email protected]] Sent: donderdag 18 februari 2010 14:30 To: [email protected] Subject: Ajax and OpenSessionInViewFilter problems Hi All, As the subject reads, I'm having some problems with Ajax and the OpenSessionInViewFilter. Here's my basic setup: I've got a page with some address info, such as street/city/zipcode. Let's call the current value of these fields V1. There is also an ajax link to open a modal panel that allows the user to look up street/city info based on the zipcode. When the modal panel opens the info V1 is passed on to the modal panel as initial value. Let's say here the user enters new info and a street/city is found, we'll call this info V2. The user then presses the submit button on the modal panel and indeed V2 is now shown on the main page. However, when I now click the ajax link to open the modal panel again, the user get's shown V1 in the modal panel as initial filling. When finally submitting the page V2 is persisted, so the information is being retained somewhere. I have debugged the application and I see the setters of my domain object being called. Also when debugging however I see that the load() method of the LoadableDetachableModel is being called when I hit the ajax link, so it seems like a new version of the object is being retrieved from the database. I thought that's what the OpenSessionInViewFilter was for, to allow for multiple requests in your view without Hibernate closing/opening the session each time and retrieving fresh copies of your objects. Here is some relevant code: OpenSessionInView setup in web.xml: <filter> <filter-name>opensessioninview</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> Submit link on my modal panel: searchResultsHolder.add(new AjaxSubmitLink("selectMatch") { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { Address address = addressModel.getObject(); address.setZipcode(foundZipcode.getZipcode()); address.setHouseNr(foundZipcode.getHouseNr()); address.setStreet(foundZipcode.getStreet().getStreetName()); address.setCity(foundZipcode.getCity().getCityName()); address.setCountry(Country.NL); address.setAddressValidated(true); for (Component component : updateList) { target.addComponent(component); } modalWindow.close(target); } }); The LoadableDetachableModel used (and is being called when I hit the ajax link): final IModel<ARF> mergedModel = new LoadableDetachableModel<ARF>() { @Override protected ARF load() { return arfService.load(arfId); } }; Many thanks for any help! Kind regards, Jonck --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
