You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/07/15 18:53:51 UTC

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


Re: How do you access an application.properties value directly from within a class?

Posted by James Mitchell <jm...@apache.org>.
You mean like this?

<bean:define id="someKey">
 <bean:message key="some.key"/>
</bean:define>

<some:otherTag value="<%=someKey%>"/>

--
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx


----- Original Message -----
From: "Mike Deegan" <mp...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, July 15, 2003 1:53 PM
Subject: Re: How do you access an application.properties value directly from
within a class?


> Hey Matt / All,
>
> Do you have an elegant way -  in scriptlet form - at the JSP level to grab
> an application.properties value to then use as a JSP expression (
<%=...%>)
> in the "value" attribute of a tag.
>
> I had tried to use the bean:message tag to get the "value" to populate
into
> the "value" attribute of another tag - that is when trying to combine two
> tags - but the page fails to compile. Can't remember the exact error msg
but
> it was along the lines of " = expected ..."
>
> I know you can use JSP expressions ( <%=...%>) in the "value" attribute of
> tags - but JSP compile fails when I try to use bean:message tag to
directly
> populate a tag's "value" attribute.
>
> So do you have an elegant way -  in scriptlet form - at the JSP level to
> grab an application.properties value to then use as a JSP expression (
> <%=...%>) in the "value" attribute of a tag.
>
> I searched for some time for an answer on this but got lost in the maze.
> Maybe the wording of my searches let me down.
>
> Or should I be attempting to do this in another way ... without scriptlets
> ... to get an application.properties value to populate into the "value"
> attribute of another tag.
>
> Any help appreciated ...
> Mike
>
> ----- Original Message -----
> From: "Raible, Matt" <Ma...@cable.comcast.com>
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Sent: Tuesday, July 15, 2003 10:53 AM
> 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


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


Re: How do you access an application.properties value directly from within a class?

Posted by Mike Deegan <mp...@hotmail.com>.
Thanks Konstadinis and James !
Appreciate the help - had a mental block after a week long Stampede party
here in Calgary.

Mike

----- Original Message ----- 
From: "Konstadinis Euaggelos" <Va...@eurodyn.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Saturday, February 15, 2003 1:00 PM
Subject: Re: How do you access an application.properties value directly from
within a class?


> You can use this,
> <bean:define id="key"><bean:message key='myKey'/></bean:define>
>
> You can use the key as a scriplet   <% =key%>
>
>
> This solution works also in the following case ,
> if you want to display a title in your button if your write title =
> "<bean:message key='myKey'/>"
> it willn 't work ,
>
> Following the above solution it works,
>
> <html:button property="previous" styleClass="Button"
> title="<%="["+key+"]"%>" >
>             <bean:message bundle="BUTTON_RESOURCE_KEY"
> key="button.previous"/>
> </html:button>
>
>
>
>
>
> ----- Original Message -----
> From: "Mike Deegan" <mp...@hotmail.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, July 15, 2003 7:53 PM
> Subject: Re: How do you access an application.properties value directly
from
> within a class?
>
>
> > Hey Matt / All,
> >
> > Do you have an elegant way -  in scriptlet form - at the JSP level to
grab
> > an application.properties value to then use as a JSP expression (
> <%=...%>)
> > in the "value" attribute of a tag.
> >
> > I had tried to use the bean:message tag to get the "value" to populate
> into
> > the "value" attribute of another tag - that is when trying to combine
two
> > tags - but the page fails to compile. Can't remember the exact error msg
> but
> > it was along the lines of " = expected ..."
> >
> > I know you can use JSP expressions ( <%=...%>) in the "value" attribute
of
> > tags - but JSP compile fails when I try to use bean:message tag to
> directly
> > populate a tag's "value" attribute.
> >
> > So do you have an elegant way -  in scriptlet form - at the JSP level to
> > grab an application.properties value to then use as a JSP expression (
> > <%=...%>) in the "value" attribute of a tag.
> >
> > I searched for some time for an answer on this but got lost in the maze.
> > Maybe the wording of my searches let me down.
> >
> > Or should I be attempting to do this in another way ... without
scriptlets
> > ... to get an application.properties value to populate into the "value"
> > attribute of another tag.
> >
> > Any help appreciated ...
> > Mike
> >
> > ----- Original Message -----
> > From: "Raible, Matt" <Ma...@cable.comcast.com>
> > To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> > Sent: Tuesday, July 15, 2003 10:53 AM
> > 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
> >
> >
>
>
> ---------------------------------------------------------------------
> 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


Re: How do you access an application.properties value directly from within a class?

Posted by Konstadinis Euaggelos <Va...@eurodyn.com>.
You can use this,
<bean:define id="key"><bean:message key='myKey'/></bean:define>

You can use the key as a scriplet   <% =key%>


This solution works also in the following case ,
if you want to display a title in your button if your write title =
"<bean:message key='myKey'/>"
it willn 't work ,

Following the above solution it works,

<html:button property="previous" styleClass="Button"
title="<%="["+key+"]"%>" >
            <bean:message bundle="BUTTON_RESOURCE_KEY"
key="button.previous"/>
</html:button>





----- Original Message -----
From: "Mike Deegan" <mp...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, July 15, 2003 7:53 PM
Subject: Re: How do you access an application.properties value directly from
within a class?


> Hey Matt / All,
>
> Do you have an elegant way -  in scriptlet form - at the JSP level to grab
> an application.properties value to then use as a JSP expression (
<%=...%>)
> in the "value" attribute of a tag.
>
> I had tried to use the bean:message tag to get the "value" to populate
into
> the "value" attribute of another tag - that is when trying to combine two
> tags - but the page fails to compile. Can't remember the exact error msg
but
> it was along the lines of " = expected ..."
>
> I know you can use JSP expressions ( <%=...%>) in the "value" attribute of
> tags - but JSP compile fails when I try to use bean:message tag to
directly
> populate a tag's "value" attribute.
>
> So do you have an elegant way -  in scriptlet form - at the JSP level to
> grab an application.properties value to then use as a JSP expression (
> <%=...%>) in the "value" attribute of a tag.
>
> I searched for some time for an answer on this but got lost in the maze.
> Maybe the wording of my searches let me down.
>
> Or should I be attempting to do this in another way ... without scriptlets
> ... to get an application.properties value to populate into the "value"
> attribute of another tag.
>
> Any help appreciated ...
> Mike
>
> ----- Original Message -----
> From: "Raible, Matt" <Ma...@cable.comcast.com>
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Sent: Tuesday, July 15, 2003 10:53 AM
> 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
>
>


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


Re: How do you access an application.properties value directly from within a class?

Posted by Mike Deegan <mp...@hotmail.com>.
Hey Matt / All,

Do you have an elegant way -  in scriptlet form - at the JSP level to grab
an application.properties value to then use as a JSP expression ( <%=...%>)
in the "value" attribute of a tag.

I had tried to use the bean:message tag to get the "value" to populate into
the "value" attribute of another tag - that is when trying to combine two
tags - but the page fails to compile. Can't remember the exact error msg but
it was along the lines of " = expected ..."

I know you can use JSP expressions ( <%=...%>) in the "value" attribute of
tags - but JSP compile fails when I try to use bean:message tag to directly
populate a tag's "value" attribute.

So do you have an elegant way -  in scriptlet form - at the JSP level to
grab an application.properties value to then use as a JSP expression (
<%=...%>) in the "value" attribute of a tag.

I searched for some time for an answer on this but got lost in the maze.
Maybe the wording of my searches let me down.

Or should I be attempting to do this in another way ... without scriptlets
... to get an application.properties value to populate into the "value"
attribute of another tag.

Any help appreciated ...
Mike

----- Original Message ----- 
From: "Raible, Matt" <Ma...@cable.comcast.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Tuesday, July 15, 2003 10:53 AM
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


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

Posted by Martin Naskovski <mn...@san.rr.com>.
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


RE: How do you access an application.properties value directly fr om within a class?

Posted by Mark Galbreath <ma...@qat.com>.
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