File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes set input of action tag from Form and action classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "set input of action tag from Form and action classes" Watch "set input of action tag from Form and action classes" New topic
Author

set input of action tag from Form and action classes

s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Hi All,

Is there any way to set the value to the input attribute of action tag in struts-config.xml from ActionForm and Action classes.

I see setInput method in ActionMapping class and I thought I can use that method to set the input value from the class. But I get java.lang.IllegalStateException: Configuration is frozen Exception

I have a simple requirement where I have a JSP with a listing that have radio buttons to update/delete from the list and add button to add to the list.

Instead of writing 3 action classes for each form action, I thought of using Dispatch action. It is because I need to validate the form fields, and validation varies for Add/Update/Delete and upon validation errors, the UI should navigate to the previous page, I need to set the what the input page is in ActionForm class..

Please suggest me a solution for this..

Thank you very much in advance and it is kind of urgent.
Thank you
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Isn't the input always the same? You only can come from 1 possible jsp in your description.


A good workman is known by his tools.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
If the declarative manner doesn't work for you, you can always do the saveErrors() way and then forward to the correct view from within the execute() of your action. It kinda screws with declarative validation though ... just a thought.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Marc Peabody
In case of Add action, I will be going to the Entry form and when user submits that form, I need to do the validation. As I am using the same Action form, upon validation error, it navigates me back to the listing but not entry form and it should because that is what configured in input attribute of action tag. Hence I was trying to upadate the input attribute by calling ActionMapping.setInput() method.

But I learned that struts configuration will be stored in the application config and as it is shared throughout the application, it will not allow you to update these parameters at runtime.

May I have to try what Nathaniel Stoddard is suggesting.

I will try and let you know.

Thank you for you response. They were helpful.
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
It worked but I am not sure if this is the correct approach.

I have set validate="false" in strus-config.xml file.

from action class i am calling validate manually and checking for ActionErrors. If ActionErrors is not equals to null then I am forwarding to the entry page and it worked.

Please let me know if you find a better solution for this.

Thank you
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

That's a pretty common solution. Just don't forget to call saveErrors() when you are handling it through the Action.
 
Consider Paul's rocket mass heater.
 
subject: set input of action tag from Form and action classes