jQuery in Action, 3rd edition
The moose likes Struts and the fly likes How to use Two Action forms into one ActionClass? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use Two Action forms into one ActionClass?" Watch "How to use Two Action forms into one ActionClass?" New topic

How to use Two Action forms into one ActionClass?

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
I want to use two Actionforms into a action class? Can I use it?
Currently I am using it but it is giving me error like :-
11:15:10,984 ERROR [[action]] Servlet.service() for servlet action threw exception
java.lang.ClassCastException: com.econify.struts.form.ViewcartForm
at com.econify.struts.action.UpdatecartAction.featureditemform(UpdatecartAction.java:97)
at com.econify.struts.action.UpdatecartAction.execute(UpdatecartAction.java:86)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

What should I do if I want to use two forms inside same action class?
Please help me.
Thanx in advance.

********Deserve Before You Desire********
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
I think you should wrap the 2 forms you want into one form and use that form. I don't think you can define more than one form for one action.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can only define one ActionForm per action mapping, but more than one action mapping can point to the same Action class.

The answer to your question is yes, it is possible to have the same Action class use more than one ActionForm. Here's an example:

<action name="form1" path="/action1" type="com.mycompany.MyAction" />
<action name="form2" path="/action2" type="com.mycompany.MyAction" />

The execute() method of an Action class receives an object of type ActionForm as a parameter. It is up to you to cast this object to the correct subclass of ActionForm. The execute() method also receives an object of type ActionMapping as a parameter. You could therefore do something like this:

Consultant, Sima Solutions
I agree. Here's the link: http://aspose.com/file-tools
subject: How to use Two Action forms into one ActionClass?
It's not a secret anymore!