wood burning stoves*
The moose likes Struts and the fly likes How to share actions and JSP's among sub applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to share actions and JSP Watch "How to share actions and JSP New topic
Author

How to share actions and JSP's among sub applications?

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Hi,

I have a struts web application which has several sub applicaitons. Sub application 1 has a flow specified in it own config.xml like

Config1.xml

<action name="/actionA.do".......>
<forward name="ForwardA" path="a.jsp/>
<forward name="ForwardB" path="/actionB.do?action=prepare"/>
</action>

<action name="/actionB.do".......>
<forward name="ForwardB" path="b.jsp/>
<forward name="ForwardC" path="/actionC.do?action=prepare"/>
</action>

The same flow with a slight modification is required in another sub application.

Can i use the same action classes, action forms and JSP's defined in sub application1? More over the JSP pages uses JSTL tags which in turn uses form names for referring attributes like

<c:if test="${empty formA.name}"/>

and the form has been set in session scope. This forces me to define the same form names and action names in config.xml of sub application 2.

My questions are

1. Is there any way to reuse the same action classes, forms and JSP in the sub application2?
2. If same form names are used in both the config.xml how to differentiate the form beans in session among the sub applicaitons?

Thanks,
Ajay.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Ajay Xavier:
1. Is there any way to reuse the same action classes, forms and JSP in the sub application2?

Since your action classes and forms are part of the same application and in the same classpath, you can certainly reuse them in different modules. There is no trick to it. Just specify the classes in your action mappings. For the JSPs, just remember to specify contextRelative="true" in the <forward> elements of your action mappings.
Originally posted by Ajay Xavier:
2. If same form names are used in both the config.xml how to differentiate the form beans in session among the sub applicaitons?

My first question is why are you using session scope for your forms? Most forms will work just fine in request scope, and it is much easier on system resources.

If you have a legitimate reaon for putting forms in session scope, you can still reuse the same ActionForm class in different modules, but you will have to make the name attribute different in the mapping for each module. Example:

in module 1:

in modue2:

[ December 16, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Thanks Merrill for you immediate response,

I do adopt the same thing(giving a different form name in both the modules) but the problem is reusing the JSP's. In my JSP's i had used JSTL tags which creates a strong coupling betweeen the JSP's and config.xml (since they define the form names i have to use the same names in my JSP). Is there any ways i can reuse my JSP's?

Thanks,
Ajay.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you look at what modifications it would take to switch your ActionForms to request scope. That way you don't have to worry about using the same form name in different modules. If there are data items that must persist between requests, you might look at saving them in hidden fields or in a relational database.
Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Thanks Merill,

Is there any other option than switching the action form scope? because that will be like reengineering my whole project ?

Regards,
Ajay.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The only other thing I can suggest would be to examine the cases where a user might navigate from a Jsp in one module to the same JSP in another module. There may be a way that you can set up logic in your Action class so that you initialize the ActionForm when a user first navigates to that page. That way, even if the ActionForm is alread in the session, it won't matter because you've made sure that old data was removed before the JSP is displayed in the current module.
 
Don't get me started about those stupid light bulbs.
 
subject: How to share actions and JSP's among sub applications?
 
Similar Threads
Can an action class forward to another action class?
Struts validation problem..
Redisplaying a page after validation due to validation errors?
How to use Formbean's validate method?
Link Only To Actions....