I posted this a few weeks ago as a patch, when it should more properly have
been a proposal. Here, then, is the proposal:

A problem with the current <bean:message> tag is that the only way to
specify the message resource key dynamically is by using a JSP expression.
This leads to the use of the following pattern:

    <bean:define id="myKey" name="myForm" property="myKeyProperty"
type="java.lang.String"/>
    <bean:message key="<%= myKey %>"/>

An alternative is to have the Action look up the key and set the resulting
string value in the property for use on the JSP page via <bean:write>. This
doesn't feel right, because the responsibility for looking up the
appropriately localized text is then divided between the Action and the JSP
page.

By enhancing the <bean:message> tag to allow it to obtain the message
resource key from a bean property, we can simplify the above example to:

    <bean:message name="myForm" property="myKeyProperty"/>

Here, the 'name' and 'property' attributes are used to obtain the message
resource key from a bean. That key is then used as if it had been specified
using the 'key' attribute.

I believe this proposal would enhance the i18n functionality of Struts by
allowing dynamic specification of messages, while delegating the resolution
of the actual message text to the view.

Comments?

--
Martin Cooper



Reply via email to