File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2.0.11 <s:textfield> label alignment issue.

 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic