aspose file tools*
The moose likes Struts and the fly likes message resource bundles question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "message resource bundles question" Watch "message resource bundles question" New topic
Author

message resource bundles question

Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
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..


SCJP 1.4 | OCWCD JEE 5
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
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

Joined: Feb 15, 2005
Posts: 4864
Ronan,

Thanks for pointing that out! I was unaware of that behavior, and it's a good thing to know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: message resource bundles question