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.
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 ]
Joined: Feb 26, 2005
One solution that I used now, is to store the common data in a context like request or session.