• 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 1.x] action subclassing / data common to many actions

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

I have common data at the top and at the right side of all pages.

Struts 2

In struts 2, I put the data, and the retrieval of these data from a common base class that all action classes extend; with the use of template method design pattern.

That way, the method that retrieves these common data is executed, after calling any subclass' main action method like execute().

Therefore, the data is available to all jsps corresponding to all those actions that extended the base action class.

The jsps refer to the data variables without needing to specify the action class name, or the base action class that it extended, because struts 2 will search for it and find it in the value stack.

It is therefore modularized. Both the class codes and the jsp fragment file for the common data on the top and right side of pages, are separated from all the pages, and can change with low impact.

Struts 1.x

In struts 1.x, how can do it?

In <action></action>, there is only 1 'name' attribute which relates to the corresponding form.

In the common jsp fragment file that I include in all pages, I must refer to the common data, but there is a 'name' attribute to specify. I cannot put the subclass form because this is a jsp fragment included in all pages, which may or may not use another form.

Neither can I put the form base class name on the 'name' attribute, because the form base class is not designed to be instantiated by itself; it is designed to be subclassed.

======

Any ideas will be appreciated.
[ May 31, 2008: Message edited by: Jesus Angeles ]
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One solution that I used now, is to store the common data in a context like request or session.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest you use Struts Tiles instead.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

I thought so too. Now I cannot delay to study Tiles anymore.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
I'd suggest you use Struts Tiles instead.



Hi Merrill,

Since the sublayout which contains the presentation for the common data, is loaded by all pages, is it right to say that, that data (object) should now be included in all form classes?

And if that is so, it is a perfect design to use a superclass form where all those common data are put? ....and all forms will extend that superclass form?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic