Solved

How to use two action forms inside same action class?

Posted on 2006-07-13
3
290 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 94
immutable object concept 5 127
JSP How to use numberFormat to display a negative number without parenthesis? 1 178
Java Exception example issues 11 84
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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