Solved

How to use two action forms inside same action class?

Posted on 2006-07-13
3
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seveā€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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