Hi Greg,
Thanks for your help. I hadn't noticed the bundle option on html:messages -
doh!
It does seem rather restrictive though. It kind of makes it hard when (like
I'm doing) you want to build some sort of common jar file for use on a number
of apps. You either have to duplicate your core message file in each project
and add to it as necessary. Or try and work out some other technique.
I don't know if any of the struts developers are watching this. but could I
suggest that all messages files referenced under the same key in the
struts-config.xml file are regarded as one and scanned rather than just the
last one. It would probably be even better if they where scanned in order for
a particular message too. That way, it would be possible to override messages
if desired by simple redefining them in a higher level file.
cio
Derek.
On Thursday 04 December 2003 17:15, Greg Reddin wrote:
> Derek Clarkson wrote:
> > Hi all,
> > I've just subscribed to this list and would appreciate any help you can
> > give. I've been trying to get resources bundles to work. I have a jar
> > file which is used on several projects and contains some core business
> > beans. It also contains aproperty file with a basic set of messages for
> > various errors.
> >
> > In the project I am currently working on I have another properties file
> > which contains more project specific messages. The problems is that I
> > cannot find out how to access these messages in an Action.
>
> Derek,
>
> If my understanding is correct, neither ActionMessage nor ActionMessages
> do any resolution of the message so they are agnostic of the resource
> bundle the message is in. It's just a collection of keys until you try
> to resolve them on a JSP page. At that point you specify which bundle
> the message should be resolved from.
>
> > I've read a lot on the web, but most of the docouments talk about how you
> > do it using jsp tags. In actions I can access messages using the
> > ActionMessage class which are stored in the default properties file.
>
> This is not actually corect. In actions, the ActionMessages object is
> just a collection of keys. Again, it's agnostic of which properties
> file the message comes from.
>
> > In my
> > struts-config.xml though, I can only have one properties file as default
> > and the other I have to provide a key for.
> >
> > I can't find any way to tell ActionMessage what key to use to access the
> > messages I want to use. I can do it using a MessageResources class, but
> > it only provides the completed message Strings, and ActionMessage only
> > accepts property keys.
> >
> > I must be missing something, or there is a gap between these two ways of
> > handle messages. All I want to do is (in an Action) retrieve a message
> > from a specific properties file and display it in a document using
> > <html:messages>. This shouldn't be this hard, any ideas ????
>
> In your action class create and save the ActionMessages collection, then
> use the "bundle" attribute of the <html:messages> tag in your JSP to
> resolve the messages from a specific resource file.
>
> I do see how it would be desireable for your case to be able to specify
> the bundle when you create the message. Then you could use one
> <html:messages> tag to display all your messages no matter what bundle
> they are in. But the Struts approach is to specify the bundle to
> resolve a message as close to the view as possible and let the rest of
> the Frameowrk not care.
>
> Another option for you would be to store messages in multiple
> collections and use both the "name" and "bundle" attributes of the
> <html:messages> tag to find and resolve from a different bundle:
>
> -----------------------------------------------------------------
> In action:
>
> ActionMessages myMessages = new ActionMessages();
> myMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
> "foo.bar"));
> request.setAttribute("myCollection", msgs);
>
> ActionMessages messages = new ActionMessages();
> messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
> "some.message"));
> saveMessages(request, messages);
>
> -----------------------------------------------------------------
> In JSP:
>
> <%-- To display messages in custom bundle --%>
> <html:messages id="msg" name="myCollection" bundle="myBundle"/>
> <bean:write name="msg"/>
> </html:messages>
>
> <%-- To display messages in default bundle --%>
> <html:messages id="msg">
> <bean:write name="msg"/>
> </html:messages>
>
> Greg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
Regards,
Derek Clarkson
Analyst/Programmer
Waterwerks Pty Ltd
Melbourne
Australia
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]