You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Samuel Rochas <sa...@andinasoft.com> on 2004/04/29 20:11:34 UTC

Multiple action for one (1) form

Hello,

Before struts, I used to handle that with some javascript and hidden 
action wich I evaluated in my servlet.

What is the best way to define different actions for the same form with 
struts?

Thanx
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Multiple action for one (1) form

Posted by Riyad Kalla <rs...@email.arizona.edu>.
Yes with the html:submit, something like:

<html:form action="/your/path/addUser.do">
    <html:submit />
</html:form>

then in your struts-config:
<action
    name="userForm"
    path="/your/path/addUser"
    type="your.package.AddUserAction">
    <forward name="success" path="/userSuccessfullyAdded.jsp" />
    <forward name="failure" path="/userAddFailed.jsp" />
</action>

Samuel Rochas wrote:

> Helle Riyad,
>
>> And then you setup your 3 actions in your struts-config:
>> <action name="userForm" type="AddUser" validate="true" />
>> <action name="userForm" type="EditUser" validate="true" />
>> <action name="userForm" type="RemoveUser" validate="false" />
>
> Ok. How do I trigger the action type in the jsp file? In the 
> html:submit tag?
>
> Does that mean, I have the following classes: AddUserAction, 
> EditUserAction and RemoveUserAction?
>
> Sincerly
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.com  ---------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Multiple action for one (1) form

Posted by Samuel Rochas <sa...@andinasoft.com>.
Helle Riyad,

> And then you setup your 3 actions in your struts-config:
> <action name="userForm" type="AddUser" validate="true" />
> <action name="userForm" type="EditUser" validate="true" />
> <action name="userForm" type="RemoveUser" validate="false" />
Ok. How do I trigger the action type in the jsp file? In the html:submit 
tag?

Does that mean, I have the following classes: AddUserAction, 
EditUserAction and RemoveUserAction?

Sincerly
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Multiple action for one (1) form

Posted by Riyad Kalla <rs...@email.arizona.edu>.
I'm not sure about a 'best way', but do know of what I think is the 'only way' 
to do this :)

Lets take the following situation:
You are writing an admin module that allows you to add a user, edit a user and 
lets say remove a user. That is 3 actions.

Lets say you want 1 form, UserForm, to use with those 3 actions, you define it 
as such:

UserForm:
String name;
String email;
String password;
Date joinDate;

And then you setup your 3 actions in your struts-config:
<action name="userForm" type="AddUser" validate="true" />
<action name="userForm" type="EditUser" validate="true" />
<action name="userForm" type="RemoveUser" validate="false" />

I think the key to sharing forms to knowing when you need to validate and when 
you don't need to. In this example I don't validate in the removeUser action 
because its likely that all the action needs is just 1 field, the user email 
so it can correctly do a SQL query to remove him.

In the other two actions, you are adding a new user and editing/updated the 
users fields, both of which should have the same validation criteria (i.e. no 
empty email address, name must be longer than 1 character... stuff like 
that).

Atlesat this is how I know to do this, does anyone else have a solution?
-Riyad


On Thursday 29 April 2004 11:11 am, Samuel Rochas wrote:
> Hello,
>
> Before struts, I used to handle that with some javascript and hidden
> action wich I evaluated in my servlet.
>
> What is the best way to define different actions for the same form with
> struts?
>
> Thanx
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.com  ---------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org