Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts 2.0.11 <s:textfield> label alignment issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2.0.11 <s:textfield> label alignment issue." Watch "Struts 2.0.11 <s:textfield> label alignment issue." New topic
Author

Struts 2.0.11 <s:textfield> label alignment issue.

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 02, 2005
Posts: 443
    
    1

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

Joined: Mar 02, 2005
Posts: 443
    
    1

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 02, 2005
Posts: 443
    
    1

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!
 
GeeCON Prague 2014
 
subject: Struts 2.0.11 <s:textfield> label alignment issue.