Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2 - Internationalize Submit Text

 
Scott Selikoff
author
Saloon Keeper
Posts: 3903
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to internationalize the text in a submit button using package.properties file. The properties file works for all other fields but seems to be ignored in submit/reset buttons. I've tried a number of combinations including:
<s:submit value="widgetform.submit"/>
<s:submit value="${widgetform.submit}"/>
<s:submit value="#{widgetform.submit}"/>
<s:submit label="widgetform.submit"/>
<s:submit name="widgetform.submit"/>
Where "widget.submit" is a key to a text value defined in my properties file. Most of these end up with the button value displaying "widgetform.submit". Am I missing an obvious combination or is this a broken feature?

The long (invalid) form for what I'd like is:
<s:submit value="<s:text name="widgetform.submit"/>"/>
If anyone has a solution using the long form that doesn't throw a compilation error due to the embedded tag, I'll take that too.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) That would try to get a value from an action property.
2) Same, but would fall back to a JEE scoped attribute if no action property.
3) That's JSF (or unified) EL, or whatever it's called.
4) I don't think submit buttons have labels.
5) Similar to #1.

Personally I'd go the route of the other tags first and try the "key" attribute.

If that failed, I'd use OGNL's method call support:

 
Scott Selikoff
author
Saloon Keeper
Posts: 3903
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, "key" worked. I still feel like this is a guessing game. I mean many of the other fields use name to establish the same thing, it feels like submit/reset should use name as well.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, they don't: "name" defines the action property used to fill an input element and the name of the element that will be submitted (and stored into the action property). It doesn't have anything to do with I18N--it's just defining the form element name and, if there's no "value" attribute, will pre-load the input element w/ the action property's value.

The "label" property is expecting a string to use as the text element's label: submit buttons, however, don't have a separate label. Labels are the things that appear next to the form fields; submit-type things are different because labeling them would be a little redundant. The string used as the label can be immediate (the default) or the result of an arbitrary method call--in the example I provided I used ActionSupport's getText() I18N support.

The "key" property is just shorthand for a set of name/value/localized label attributes; it's the only attribute that automagically does I18N.
 
Scott Selikoff
author
Saloon Keeper
Posts: 3903
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So all the places I'm using 'name' that happens to resolve the i18n should be 'key'? I don't disagree that "key" is the way to go for submit/reset buttons, but it seems like confused redundancy that "name" does i18n throughout a dozen other tags, and not these two.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of S2 are you using? I don't see that behavior under S2.1, although it may work in S2.0.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic