aspose file tools*
The moose likes Struts and the fly likes [struts 1.x]  action subclassing / data common to many actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[struts 1.x]  action subclassing / data common to many actions" Watch "[struts 1.x]  action subclassing / data common to many actions" New topic
Author

[struts 1.x] action subclassing / data common to many actions

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
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

Joined: Feb 26, 2005
Posts: 2046
One solution that I used now, is to store the common data in a context like request or session.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you use Struts Tiles instead.


Merrill
Consultant, Sima Solutions
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
Thanks.

I thought so too. Now I cannot delay to study Tiles anymore.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [struts 1.x] action subclassing / data common to many actions
 
Similar Threads
Client-side validation using ValidatorActionForm
ActionForward and Forward Action
about struts
Populating List thru logic:iterate , The modified List is not reaching action
<jsp:invoke> for Tag files