Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts Localization Properties File keys with '@'

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I started working at a new project from another unfortunately deceased colleague. I noticed a strange thing: In the Localization-Properties-files there are many keys like

salutation@miss.mail=Dear Miss or
customer.register-tool@retailerZip=Post code

I have never seen Properties-Keys with '@' as a part of it. I also can't find any documentation of this anywhere. If I google it I can't find anything. Does someone here have any clue of what this might be? I guess it is some kind of scope, like depending on the action, because both Examples above are being referenced to in the JSP with only the part after the '@', e.g.

<struts:text name="retailerZip" />

Hope you do understand what's buggin' me.

 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2 uses standard Java classes for localization. The base class for that functionality is java.util.Properties. I don't see anything in that documentation or the Java Tutorial that specifically addresses what you are seeing. I built a simple test class to print out some properties:



Here is my property file:


And when I run it, here is the output:


So it looks like using the full property key with an '@' sign works, as does just using the portion after the '@' sign. Note that using the portion before the '@' does not work.
I don't know what purpose this function would have if it is intentional.
 
Sascha Kleiber
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just figured out what is used for:

if one and the same JSP is being referenced from different Struts-Actions (via tiles etc.) and there's a struts text tag like



I can write two different properties for this field, depending on the Action where it is used. If it is used in "administration", I create a property like



where it is a different text as if being referenced from "customer", where the property



is being used. Strange thing is, I can't find any documentation about that. If it is Legacy code from a colleague before me, I don't know how he managed to achieve a feature like that. I'd love to know where I can find code which could do that. I tried the text.ftl file, but couldn't find anything here... Any suggestions of how to find something via IDE search (using Intellij)?
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have these properties defined in separate files? I wonder if this is a way to specify which resource bundle to use.
The search order for resources starts with the action class. OGNL uses the '@' character to statically reference classes or fields, so that may be the documentation you are looking for. Of course, it is probably unnecessary, since the search order hits the action properties file first anyway.
 
Sascha Kleiber
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:Do you have these properties defined in separate files?



No,

they are all in one properties-File called "Messages.properties" (and because it is a localized Webapp in different languages, many more properties-files for each language, e.g. "Messages_en_GB.properties"). I guess that's not a default struts 2 Ressource Bundle, so I looked for a custom.resources definition, which I know is possible, strange thing is, I couldn't find any. My guess is that there is some kind of magic legacy code behind all this, nothing struts 2-out-of-the-box... :-(
 
    Bookmark Topic Watch Topic
  • New Topic