Brian Styles wrote:

Thanks for the reply Kris,


I think that setting the null property to true is probably the way to go.
I even found an exactly similar thread as what I want to do from this June.
Unfortunately there seems to be no definate answer.

http://www.mail-archive.com/[EMAIL PROTECTED]/msg69627.html

Anyone have any idea how to get rid of the "???"s

I thought that's what I just posted ;-). Obviously, it would be easy to turn that into a reusable utility method. If you really want to do it in a JSP, I suppose you could wrap it with the Jakarta String taglib (untested):


<str:strip delimiter="?">
<bean:message name="form" property="database_property"/>
</str:strip>

Otherwise, write your own taglib that strips the leading/trailing "?" characters, or use a <message-resources> element like:

<message-resources factory="...MyPropertyMessageResourcesFactory" .../>

And then create a message resource factory that produces MyPropertyMessageResources instances. MyPropertyMessageResources should extend PropertyMessageResources, but since there's no convenient way to override the behavior when returnNull == false, you'll have to c/p getMessage(Locale, String) and change:

if (returnNull) {
  return (null);
} else {
  return ("???" + messageKey(locale, key) + "???");
}

to something like:

return (returnNull ? null : messageKey(locale, key));

That's also untested, but it's the best I can come up with...

From: Kris Schneider <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: Struts Users Mailing List <[EMAIL PROTECTED]>
Subject: Re: Handling Missing Message Key
Date: Wed,  7 Jan 2004 15:16:11 -0500

Pretty sure you'd have to handle that yourself. It's probably cleaner to do it
in an action.


Action class:

String dbProp = ...;
MessageResources messages = getResources(request);
String message = dpProp;
if (messages.isPresent(dbProp)) {
  message = messages.getMessage(dbProp);
}
request.setAttribute("message", message);

JSP:

<bean:write name="message"/>

Or I suppose you could write your own tag...

Quoting Brian Styles <[EMAIL PROTECTED]>:

> Hi all,
>
> I'm using the i8ln features in the struts bean tag library
>
> I populate a form bean with info from the database, and this info acts as
> the key in a resource bundle so that I can add a international versions
> using
>
> <bean:message name="form" property="database_property"/>
>
> however, I would very much like the actual underlying property to be written
>
> out if the key doesn't exist in the resource bundle, rather than getting the
>
> nasty missing message key exception. Is this possible?
>
> thanks very much,
> Brian


--
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to