It's not a secret anymore!*
The moose likes Struts and the fly likes Struts 2 - Internationalize Submit Text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - Internationalize Submit Text" Watch "Struts 2 - Internationalize Submit Text" New topic
Author

Struts 2 - Internationalize Submit Text

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

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

Joined: Sep 29, 2008
Posts: 12617

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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

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

Joined: Sep 29, 2008
Posts: 12617

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
 
subject: Struts 2 - Internationalize Submit Text
 
Similar Threads
submit values incorrect in internet explorer
s:submit
how do I submit without a submit button textarea contents
Struts Form With AJAX
submit buttons in form