This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes Putting a modeldriven object into session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Putting a modeldriven object into session" Watch "Putting a modeldriven object into session" New topic
Author

Putting a modeldriven object into session

Kev Adams
Greenhorn

Joined: Oct 27, 2009
Posts: 22
Hi everyone,

I have a Search action that implements ModelDriven. Once a user enters his search criteria, I want that information put into the Session so that after the user has performed other functions on other pages (add, change, delete, etc...) and the user comes back to the Search page, the search will be performed again with the last search parameters.

To do this, I created an interceptor that will inject the search criteria object into my search action.

The problem I'm having is, *when* do I put my search criteria object into the session? I'm using the paramsPrepareParamsStack and after the first "params" interceptor fires, the request parameters are not in my model object -- yet. They don't get put into the model object until the 'modelDriven' interceptor fires, at least, that's what I see when I debug my action.

Any ideas?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Add it to the session in the action that processes the form. This kind of behavior doesn't belong in an interceptor.
Kev Adams
Greenhorn

Joined: Oct 27, 2009
Posts: 22
David,

That's what I'm doing. In the action that processes the search form, I'm putting the criteria into the session, and I'm letting an interceptor inject that criteria back into the action when the user comes back to the search page after having done something else.

The problem I'm having is that the content of the search criteria object has not been populated by the 'params' interceptor yet, because params comes before 'modeldriven' in the paramsPrepareParams stack. So, when I put the search criteria object into the session, it contains the wrong information.

Does that make sense?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I guess. You can always change the order of the interceptors.

I'm not convinced this interceptor is overly helpful, though--the same work could be done manually in the "prepare" method with a single line of code (assuming you implement SessionAware). Unless it's a general purpose "grab annotated properties from the session" interceptor, it strikes me as too "special-purpose." Interceptors are really designed for application- or large-ish-chunk-of-application-wide functionality, not a single action.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Putting a modeldriven object into session
 
Similar Threads
how to implement pojo to web form mapping in struts2
another topic for criteriaFind
Post-Redirect-Get pattern with Struts 2 ModelDriven action?
Struts 2: Is Model Driven fundamentally flawed in most uses?
Sturts2 - is there an interceptor post the action but before the result on the screen?