Wednesday, 7 May 2014

When you are using @SessionAttributes annotaion in your controller and using the same Model Attribute in multiple Request mapping methods in the same controller ; you willrun into issues if you try working in multiple tabs.

What happens is, because Session Attributes stored in SessionAttributeStore are identified by just their name, and when ever a new Object is added with same name to the store the previous one gets overridden.

Very Common scenario could be a simple create and Edit of a page where you have opened a Create new page and before hitting submit you opened an Edit page for some other record in another Tab. This Causes the Edit record Model Attribute overriding the Create new ModelAttribute in the Session Resulting is Error.

In-order to resolve this issue you will have to teach Spring not to store / retrieve the Objects from Session Attribute Store by name but by a unique identification String.

In your  *context.xml you need to define the following beans

Now the new beans that we have defined here are


  • qld.qsa.edu.au.support.SessionConversationAttributeStore
  • qld.qsa.edu.au.support.ConversationIdRequestProcessor

  • The purpose of SessionConversationAttributeStore bean is to Override the Spring's SessionAttributeStore and change the way Session Attributes are stored/retrieved/removed from Session Attribute Store. In SessionConversationAttributeStore we will define a '_cId'which will be the unique name of our attributes now.

    The Trick here is once you have stored an Attribute with a unique name, that name should always be in the Request so that we can retrieve the same attribute back for Session Store. ConversationIdRequestProcessor adds the unique name of the Attribute as hidden attribute in the form.


    Code for SessionConversationAttributeStore

    Code for ConversationIdRequestProcessor

    Make sure you remove from your context.xml You should be able to see some thing like

    In your source of the page.

    No comments:

    Post a Comment