• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Two Action forms into one ActionClass?

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Prash
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic