struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen, Gin" <Gin.C...@NielsenMedia.com>
Subject RE: How do you access an application.properties value directly fr om within a class?
Date Tue, 15 Jul 2003 19:33:49 GMT
yuk how about a much cleaner way using jstl?

<fmt:bundle basename="ApplicationResources">
    <fmt:message var="foo" key="bar"/>
</fmt:bundle>
<c:out value="${foo}"/>

Where ApplicationResources is the the name without .properties suffix.
-Tim

-----Original Message-----
From: Raible, Matt [mailto:Matt_Raible@cable.comcast.com]
Sent: Tuesday, July 15, 2003 2:53 PM
To: 'Struts Users Mailing List'
Subject: RE: How do you access an application.properties value directly
fr om within a class?


Or how about an ugly way? ;-)

<%@ page import="org.apache.struts.util.MessageResources,
                 org.apache.struts.action.Action"%>

<% 
MessageResources resources = 
    (MessageResources) request.getAttribute(Action.MESSAGES_KEY); 
%>

<%=resources.getMessage("userForm.userId")%>

Matt

-----Original Message-----
From: James Mitchell [mailto:jmitchell@apache.org]
Sent: Tuesday, July 15, 2003 12:04 PM
To: Struts Users Mailing List
Subject: Re: How do you access an application.properties value directly
from within a class?


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" <mpdeegan@hotmail.com>
To: "Struts Users Mailing List" <struts-user@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" <Matt_Raible@cable.comcast.com>
> To: "'Struts Users Mailing List'" <struts-user@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

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


Mime
View raw message