• 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

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

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ajay Xavier
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
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 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
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic