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

Reply via email to