Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using messages in resource bundle in tiles-def.xml

 
Tom Kata
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've recently started working with tiles, taking advantage of tiles-def.xml and getting rid of extraneous jsp pages. However, unlike jsp, I haven't seen, nor am I aware of, a method to extract messages from application.properties to be used within tiles-def.xml.
For example, in a jsp page, one could use <bean:message key="some.resource.message"> ... is there something similar that I could utilize within tiles-def.xml because I'd prefer to keep all messages in the resource bundle. But then again, I might be missing the point of using tiles by keeping messages in application.properties.
Let me express my gratitude in advance to any and all that shed light on this matter.
Thanks.
 
Tom Kata
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I figured out how to do this and it was much simpler than I thought: explained through example.
In your resource bundle, define a key with it's message (nothing new about this):
first.five.letters=abcde
In the tiles-def.xml, just enter the resource bundle key for the value of the 'put':
<put name="message" value="first.five.letters" />
Lastly, in the view/template jsp page use tiles:useAttribute in combination with bean:message as follows:
<tiles:useAttribute name="message"/>
<bean:message key="<%=(String) message%>" />
Voila ...
Why did I want to do this, you might be wondering ... I realize that tiles supports internationalization, but I wanted to avoid creating additional tiles xml files for each locale and keep a centralized approach to maintaining message resources
 
Jochen Maes
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice workaround, hmm might come in handy, thanks for sharing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic