Struts Message Resources

Is there a way to determine in an Action Class whether a particular message key is available in a particular message bundle.

Eg how do you determine whether the key "tranx.amount" exits in bundle "user".

The idea is that if it does not existing, I can set a default key so that the JSP will always render with this default if something is amiss.

JJ

[374 byte] By [JoeJess1a] at [2007-10-2 9:46:35]
# 1

There is a way..but its not a preffered method of doing it................

U need to get the file from the location where u have put the resource bundle and then put into properties util structure and check.....

there is no api in struts to get the resource bundle from action class i beleive........

regards

Shanu

mshanua at 2007-7-16 23:52:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If you use null="false" in the declaration of yuor MesageResources Struts will display ?tranx.amout? or something similar.

To actually test for a key you need something like

MessageResourrces.getResources().hasKey(yourkey)

I have seen the actual code while digging in the Struts source but i left it at work

pgeuensa at 2007-7-16 23:52:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
MessageResources.getMessageResources("bundlename").isPresent("key")
pgeuensa at 2007-7-16 23:52:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
struts will find default key as formname.field name is it is specified in the resource file http://www.javapeople.blogspot.com
dipalia at 2007-7-16 23:52:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
This is ok and I am using the null="false". But it works only if the key is wrong. It does not work if the bundle is wrong. JJ
JoeJess1a at 2007-7-16 23:52:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...