• 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

chaining actions?

 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

In my webapplications there are footers and menus that are the same on all pages. I have added Tiles to maintain this but do I have to get the footer data and menudata in every action? In the footer there is brand and in the menu categories.

Should I use chain to let the action set brand and subcategories first? What is the best approach when you have the same data on multiple jsp pages.

I am using struts2
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U need not add code in action or chain action class, if the footer and menu jsps are correct and don't need any dynamic data, while loading the main jsp page, tiles will take care and load the other footer and menu jsps.

Whatever code needs to maintained in footer and menu, write them in corresponding jsp and specify that in tiles-defs.xml
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The brands etc are dynamic data. It depends on store and what administrators add to the db
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For anything that is conditionally displayed in a header or footer, I usually put that information in session scope. So for example, if I have a toolbar.jsp that shows a link for "admin options" only if the user is logged in as an admin, when the admin logs on, I set a session variable or I put an object with preferences in the session, and the toolbar.jsp tile looks like this:

This is quick and dirty since I'm rushed for time, but it should give you an idea on a potential option.

Or, if you can't use session objects, you should be able to use request.setAttribute("whatever", whateverObj) in every single action and in your tiles check for the values in that whateverObject. It might be best to extend Action and put those calls in a preprocess method so it is only in one place.

[ May 18, 2007: Message edited by: Dom Lassy ]
[ May 18, 2007: Message edited by: Dom Lassy ]
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

I want to use filters or Interceptors to set session data and open , close hibernate sessions before reaching the Action.

How can I get this chain to work

--- populate object that all actions need
--- execute the action
--- do some clean up that all actions need

I look into the Interceptor interface and abstract classes but it seems that they first execute and then in reverse order. I do not need to populate in reverse order? Any suggestions?
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How can I get this chain to work

--- populate object that all actions need
--- execute the action
--- do some clean up that all actions need



Create a class that extends Action, called ActionExt. In ActionExt create a preProcess() method and "populate object that all actions need". In ActionExt declare this method:

Also, in ActionExt create a postProcess() method to "do some clean up that all actions need".
Finally, in ActionExt do this:


Then have all of your actions extend ActionExt and implement the abstract executeAction method.

EDIT: There are other ways to handle exceptions so you don't have to implement the exception handling the way I posted.

[ May 18, 2007: Message edited by: Dom Lassy ]
[ May 18, 2007: Message edited by: Dom Lassy ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use an approach like Dom suggests. I populate the data needed for headers in a base action class. A filter approach like what Struts 2.0/WebWork uses seems cleaner and easier to configure on a per action bases. The template pattern and inheritance can be very powerful, but it does have limitations.

- Brent
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic