• 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

message resource bundles question

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm using struts 1.2.9..

Basically i have a 2 message resources bundles - once called "client" and the other called "server". how do i in a JSP check if a certain key exists in the client bundle and render it, but if it doesnt exist in the client bundle then render the value of the key in the server bundle. both bundles have a key name "customer.name" for example.

i know that to render the bundle i do:
<bean:message key="customer.name" bundle="client"/>
or
<bean:message key="customer.name" bundle="server"/>

how can i check the first one to see if the key exist in the client bundle (can i use something like <logic resent>
I could code some java in the action class that forwards to this jsp but that seems a bit hacky. any help would be great..
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ronan Dowd:
I could code some java in the action class that forwards to this jsp but that seems a bit hacky.


I'm sure there is a way that this could be accomplished in the JSP, but any way you look at it, you'd be adding several lines in your JSP just to display one message. Since the goal of an MVC application is to have as little logic as possible in the JSP, that solution seems way more "hacky" than putting logic in your action class. One way to make it a little more elegant would be to put the message as a property in your Actionform and then have your Action class populate the property.
 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi actually just noticed..

If i do

<bean:message key="customer.name" bundle="client"/>

then struts looks in client bundle for this key, if it isnt found it seems looks in the default bundle automatically.

So just having the above line seems to work fine :-)
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ronan,

Thanks for pointing that out! I was unaware of that behavior, and it's a good thing to know.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic