> I think that the best thing to do would be to not use the text of
>the button at all. If you use the text you will need to change the
>code as well if you decide to change the text on the button by
>editing the property file. (And if you get internationalization into
>the picture it will be even worse.)
I disagree on this.
By accessing the properties file I am actually avoiding having
to modify the code if the button text changes. After all, I am accessing
the property from the JSP using a tag, and what I try to do in the perform
method is the same: access the value of the property.
I won't have a static text in my method, I will have something like
getProperty("button.edit") in the conditional statement.
So a change of the property value will be mapped to both the JSP tag,
and to the (dynamic) conditional statement in the perform method.
Martijn Spronk wrote:
> Hi all,
>
> I'm pretty new to struts, and just started developing a fairly
> simple app, however taking a bit beyond the standard example
functionality.
>
> I have a (probably) pretty simple question:
> I'm in the perform method of the Action class, processing a form submit,
but
> want to
> forward to different mappings depending on which button was pressed.
> In the JSP I am using the ApplicationResources.properties file to create
the
> button text for the
> different buttons, so now I need to access this text also to determine
which
> action to
> take.
>
> So how do I access the descriptions from the properties file in the Action
> class?
>
> my form:
> -------------------
> <tr>
> <td colspan="5" align="right">
> <html:submit styleClass="bodyform">
> <bean:message key="button.cancel"/>
> </html:submit> </td>
> <td>
> <html:submit styleClass="bodyform">
> <bean:message key="button.edit"/>
> </html:submit> </td>
> <td>
> <html:submit styleClass="bodyform">
> <bean:message key="button.confirm"/>
> </html:submit></td>
> </tr>
> -------------------
>
> So what do I put at the ... in the following fragment of the perform()
> method to
> be able to get the textual value of the button.cancel and button.edit?
> -------------------
> String submit = request.getParameter("submit");
> // Forward control depending on which button was pressed
> if (submit.equals(...))
> return (mapping.findForward("cancel"))
> else if (submit.equals(...))
> return (mapping.findForward("edit"))
> -------------------
>
> Thanks,
> Martijn.