You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Galbreath <ma...@qat.com> on 2003/07/15 19:13:05 UTC
RE: How do you access an application.properties value directly fr om within a class?
Nice, clean, elegant solution - thanks a lot, Matt!
-----Original Message-----
From: Raible, Matt [mailto:Matt_Raible@cable.comcast.com]
Sent: Tuesday, July 15, 2003 12:54 PM
To: 'Struts Users Mailing List'
Subject: RE: How do you access an application.properties value directly fr
om within a class?
I forgot to add the simplest way in an Action class:
MessageResources resources = getResources(request);
resources.getMessage("keyName");
-----Original Message-----
From: Raible, Matt
Sent: Tuesday, July 15, 2003 10:51 AM
To: 'Struts Users Mailing List'
Subject: RE: How do you access an application.properties value directly fr
om within a class?
If you're just looking for the values, grab it as a resource bundle. Here's
how I grab it in a Business Delegate:
// Get the application's messages resources
ResourceBundle resources =
ResourceBundle.getBundle("ApplicationResources");
String appDBVersion = resources.getString("webapp.db_version");
And then of course, there's errors and messages - where it grabs it
automagically:
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("errors.existing.user",
userForm.getUsername(),
userForm.getEmail()));
messages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("user.deleted",
userForm.getEmail()));
And lastly, you can get it from the servlet context in a servlet outside of
struts:
MessageResources resources =
((MessageResources)
getServletContext().getAttribute(Globals.MESSAGES_KEY));
resources.getMessage("userFormEx.username");
HTH,
Matt
-----Original Message-----
From: Mark Galbreath [mailto:mark_galbreath@qat.com]
Sent: Tuesday, July 15, 2003 10:28 AM
To: 'Struts Users Mailing List'
Subject: How do you access an application.properties value directly from
within a class?
When Struts load, it grabs application.properties and stores it's keys and
values somewhere. From within an action class I need to access a value in
application.properties. How could one do this?
tia,
mark
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org