• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2.0.11 <s:textfield> label alignment issue.

 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to have a label displayed alongside (on the left) a textfield in my form. I want the form to use internationalization so I've go the labels in a properties file according to the locales. The way I am try to get this to work is as shown below:-


Now the variable 'key' contains the associated value stored in the properties file. I can access it using:-

or

I am not able to get that as the label to the textfield. I tried :-

and

Both of them result in the entire string between the quotes getting displayed, eg: "<s:property value='%{key}'/>".

I tried using the <s:label> tag as in:-

But all the label appear one after the other horizontally on a single line with each of the corresponding form elements are arranged one below the other in a vertical fashion.

How can this be corrected?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally the <s:textfield> (and other form tags) would use the "key" attribute to define both the label key and the property name.

If you're dead-set on not doing that, you'll have to use OGNL to call the action's getText(...) method, passing in the label key based on however you want to name the key. IMO this is a bad idea, but it works. Is there any reason you can't just use the "key" attribute?
 
Rajkamal Pillai
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using the key attribute earlier but I am not getting the value associated with the key altogether. That is the reason why I moved on to the ways mentioned above. Do I have to specify my properties file in some way for the key attribute to work?
 
Rajkamal Pillai
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think I managed to get this one solved :-) I enclosed my elements in a <s:i18n> and specified the name of the properties file with the 'name' attribute and the all worked like a charm!

Thanks David.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't need to go to all that trouble.

I just use the "key" attribute and put the property files in appropriate locations and no extra plumbing is required.
 
Rajkamal Pillai
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool! I ran to the documentation and they have mentioned the folders where and the order in which resource bundles are searched for:-

Struts 2.0.11 Documentation

Thanks once again!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic