You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hezjing <he...@gmail.com> on 2008/02/04 07:04:24 UTC
[S2] Multiple buttons in a form
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".
What is the good way to implement a form with multiple buttons, while
maintaining the i18n?
--
Hez
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Multiple buttons in a form
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
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