Ted,

> I'm probably +1 on this. I'm just not sure when you would want to
> specify the key dynamically. I'd also wonder if there's a need to
> specify the key dynamically, do we need to offer the same for the bundle
> too?

One example of where this would be useful in our app is this. Suppose I have
a Policy object, and suppose a policy has a type, represented by an integer.
On my policyView page, I want to display the user-friendly policy type. What
I'd like to be able to do is map from the integer to a resource key in the
action, and then have the JSP page obtain the appropriately localised text.

I don't see a need to specify the bundle dynamically.

> Meanwhile, I also wonder if we should have "textKey" and "bundle"
> attributes for the html:link and html:submit tags, so you could use the
> < ... /> form instead something like <html:link ...><bean:message ...
> /></html:link>. This would be consistent with how <html:image> and
> <html:img> work.

I have done this for some of our tags that are derived from Struts tags. The
original reason for doing this was reducing code size (the "Illegal target
of jump or branch" nightmare), but it turned out to be convenient and easier
to write/read.

--
Martin Cooper

>
> Also, I should play with this myself first, but since we're talking
> i18n, if I have internationalized a button, and have multiple buttons,
> then HTTP is going to submit the i18n label as a value. How do I parse
> that in the Action, can I do a reverse lookup in the resource based on
> the actor's locale? Or am I overlooking something?
>
> </OT>
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 737-3463.
> -- http://www.husted.com/about/struts/
>
> Martin Cooper wrote:
> >
> > 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