Solved

How to use two action forms inside same action class?

Posted on 2006-07-13
3
291 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:Econify
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
anumalas earned 500 total points
ID: 17106195
Hi

Using DispatchAction and LookupDispathAction you can have two forms for one action.

As per best practices each action can have only one form. in execute() method we will pass the actionform instance as a parameter.

There is one alternate way to hold form data

public class YourActionForm()
{

private SomeOtherFormDataBean someExtra; //This is the bean contains some properties, getter and setters;

public void setSomeExtra(){} // setter of your bean
public SomeOtherFormDataBean getSomeExtra(){} // getter of your bean
}

write bean

in action class execute method

form.getSomeOtherDataBean.setSomeProperty() // to set data values;

like above you can use multiple beans in a single form to store/retrive different set of properties instead of using muiltiple forms

Hope this will help :)
0
 

Author Comment

by:Econify
ID: 17119949
Hi anumalas .
thanx for ur help. I found some other way for doing above thing. I think that is easier for me.
The other solution is :- uisng two actions pointing to same action class.
I assume your solution will also work for me.
So anyways I give up all points to you.
Thanx again.
0
 
LVL 3

Expert Comment

by:anumalas
ID: 17119961
Hi Econify

good go ahead. :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 145
spring dependency injection using java config 2 91
servlet concurrency 13 122
jsp insert to database example 2 66
The world seems to conceive of a curious bubble separating IT from “the business.”  More so than just about any other pursuit in the commercial world, people think of IT as some kind of an island.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question