• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 and passing data using interceptors

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm new to Struts and have a question regarding how data is passed from an Action (in Struts 2) to the JSP which one is redirected to after the action is executed. Reading the documentation on Struts 2, I've found that using the Scope Interceptor one can specify Action properties to be bound to the session or application scope. This is configured in struts.xml with the <interceptor-ref name="scope"> tag and then setting the appropriate parameters. See http://www.twdata.org/backups/WW/scope-interceptor.html

Now, say I access an EJB from an Action. The method of the EJB returns some data. Is it good programming practice (in Struts) to store this data in the session object, later to be accessed from a JSP? This should allow me to pass the data, but perhaps there is some other alternative which is preferred. Storing information in the session object would maybe be good practice for data such as user id, contents of a shopping cart, etc. The scope I believe I am interested in is request scope, since the data returned from the invoked EJB method is data from an Amazon.com search, only to be used in the JSP displayed immediately after the execution of the Action.

Would the preferred method in my case then be to implement the ServletRequestAware interface in the Action and store data of interest in the request object? I can't find any interceptor that does this. I'm sure one can create user defined interceptors, but if there's a standard method for this functionality provided by the framework, then I guess that would be the preferred way to go.

I'm grateful for any input on the matter. Cheers.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 2 question huh....this could get confusing since Struts 1.x and Struts 2 are so different. I played around a little with WebWork. My understanding is that you would store properties that are accessed by your JSP as properties of your action class. WebWork (and Struts 2) has a concept called a Value Stack. It is a little hard to explain and I don't fully understand how it works (magic?) but your Action class is placed on the top of the value stack where its properties can be seen by your JSP page.

If you search around the web for phrases like "WebWork Value Stack" I am sure you can find out more information. Since I don't get the feeling that many people on this forum are using Struts 2 (I am not), you might have to stick around and educate the rest of us.

- Brent
 
Markus Fahl�n
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your answer. Hopfully one day I'll be able to lend someone a hand.

I hope there isn't any rule about including references to other forums. In any case, I posted the same question in one other forum and I've gotten a few replies. If you're interested, please have a look: http://www.nabble.com/Struts-2-and-passing-data-using-interceptors-tf2734105.html#a7634983
 
reply
    Bookmark Topic Watch Topic
  • New Topic