aspose file tools*
The moose likes Struts and the fly likes Call Actions in a different module from default module Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Call Actions in a different module from default module" Watch "Call Actions in a different module from default module" New topic
Author

Call Actions in a different module from default module

Jason Moors
Greenhorn

Joined: Nov 01, 2005
Posts: 4
Hi,

I've written a struts application which I've split into a number of
modules, i.e user, account etc.

I want to have a login form on the home page (within default module) to allow the user to login, however all the user management actions e.g createUserAction, loginAction, logoffAction and corresponding forms are defined in another module in the struts-config-user.xml config file.

I've created a home.jsp page which contains a form, using the
html:form and html:text tags, and have included the necessary taglibs.

I have set the form action to "/user/login", which corresponds to the
"/login" action within the struts-config-user.xml.

However when I run the application I'm getting the following error :-

javax.servlet.jsp.JspException: Cannot retrieve mapping for action /user/login
at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:810)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
at org.apache.jsp.Home_jsp._jspx_meth_html_form_0(org.apache.jsp.Home_jsp:169)
at org.apache.jsp.Home_jsp._jspx_meth_html_html_0(org.apache.jsp.Home_jsp:124)

which seems to imply that the jsp page can not see the action mapping
defined in a different module.

Therefore is it possible to use an action in a different module from
the default module. If not is there any way I could replicate this
functionality by duplicating the form bean?

Any help would be gratefully received.

Thanks

Jason
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Hi Jason

You might want to look at the Struts SwitchAction.

Cheers
Steve
[ November 01, 2005: Message edited by: Steve McCann ]
Jason Moors
Greenhorn

Joined: Nov 01, 2005
Posts: 4
Hi Steve,

Can I use the SwitchAction from a HTML Form?, all the examples seem to show the SwitchAction as a GlobalForward.

I want to have a HTML form on the homepage which POSTS the login parameters to an action in another module.

I experiemented with the SwitchAction in the past and had a problem with the STRUTS FORM bean not being found.

Thanks

Jason.
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Hi Jason

Looking in my trusty Struts Complete Reference book ...
You set up the SwitchAction in the struts-config.xml and specify the module you want to switch to and the page within it as part of your URL:

http://your.site.com/AppName/SwitchModule.do?prefix=/Mod&page=/page

where Mod is the module you want to switch to, and page is the jsp or action you want to go to inside that module.

You should be able to specify the above URL in your form's action parameter.

Steve
[ November 02, 2005: Message edited by: Steve McCann ]
Jason Moors
Greenhorn

Joined: Nov 01, 2005
Posts: 4
Hi Steve,

The problem was not in fact the switching of the module, but rather the html:form tag lookup! The FormTag does a lookup for the action and the form bean, and as the action is in a diffent module config file the lookup was failing.

I've changed the form on the login page to use HTML form syntax, instead of the html:form tag, and used the SwitchAction as you described.

Thanks for the help!

Jason.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call Actions in a different module from default module