struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: [S2] Multiple buttons in a form
Date Mon, 04 Feb 2008 06:18:28 GMT


hezjing wrote:
> Hi
>
> I have a form with multiple buttons,
>
> <s:form namespace="/user" action="updateUser" method="post">
>    <s:submit name="action" value="resetPassword" key="button.resetPassword" />
>    <s:submit name="action" value="delete" key="button.delete" />
> </s:form>
>
>
> and my action class looks like the following,
>
> public String execute() throws Exception {
>     if (action.equals("resetPassword")) {
>         userService.resetPassword(user);
>     } else if (action.equals("delete")) {
>         userService.delete(user);
>     }
>     return SUCCESS;
> }
>
>
> This action is working, except that the label/text of the buttons are
> not fetched from the i18n properties file.
>
> The buttons are displayed as "resetPassword" and "delete".
>
>   
I don't see why the I18N isn't working.  That's probably just a minor 
configuration problem.
> What is the good way to implement a form with multiple buttons, while
> maintaining the i18n?
>
>
>   
Several options:
 on s:submit, include a method="" attribute to call a method other than 
execute

<s:submit name="action" value="resetPassword" key="button.resetPassword" method="reset"/>
<s:submit name="action" value="delete" key="button.delete" method="delete />

public String reset() throws Exception {
   userService.resetPassword(user);
   return SUCCESS;
}

public String delete() throws Exception {   
   userService.delete(user);
   return SUCCESS;
}


---
Or split it into two actions:

<s:submit name="action" value="resetPassword" key="button.resetPassword" action="resetPassword"/>
<s:submit name="action" value="delete" key="button.delete" action="deleteUser/>

---

Or use a wildcard in the action

<s:submit name="action" value="resetPassword" key="button.resetPassword" action="updateUserReset"/>
<s:submit name="action" value="delete" key="button.delete" action="updateUserDelete/>

<action name="updateUser*" method="{1}" class="...">
---

I prefer the latter approach because it works best with XML validation and the ajax tags.



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


Mime
View raw message