You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Martin Naskovski <mn...@san.rr.com> on 2003/07/15 20:43:47 UTC

Re[2]: How do you access an application.properties value directly fr om within a class?

Can you also somehow check from a JSP whether a certain message resource
key is set to a certain value and then render certain HTML based on that
value, or not? Thanks

Martin

Tuesday, July 15, 2003, 9:53:51 AM, you wrote:

RM> I forgot to add the simplest way in an Action class:

RM> MessageResources resources = getResources(request);

RM> resources.getMessage("keyName");


RM> -----Original Message-----
RM> From: Raible, Matt 
RM> Sent: Tuesday, July 15, 2003 10:51 AM
RM> To: 'Struts Users Mailing List'
RM> Subject: RE: How do you access an application.properties value directly
RM> fr om within a class?


RM> If you're just looking for the values, grab it as a resource bundle. Here's
RM> how I grab it in a Business Delegate:

RM>     // Get the application's messages resources
RM>     ResourceBundle resources =
RM> ResourceBundle.getBundle("ApplicationResources");
RM>     String appDBVersion = resources.getString("webapp.db_version");

RM> And then of course, there's errors and messages - where it grabs it
RM> automagically:

RM>         errors.add(ActionErrors.GLOBAL_ERROR,
RM>                    new ActionError("errors.existing.user",
RM>                                    userForm.getUsername(),
RM>                                    userForm.getEmail()));

RM>         messages.add(ActionMessages.GLOBAL_MESSAGE,
RM>                      new ActionMessage("user.deleted",
RM> userForm.getEmail()));

RM> And lastly, you can get it from the servlet context in a servlet outside of
RM> struts:

RM>         MessageResources resources =
RM>             ((MessageResources)
RM> getServletContext().getAttribute(Globals.MESSAGES_KEY));

RM>         resources.getMessage("userFormEx.username");


RM> HTH,

RM> Matt


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org