You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Billy Ng <ev...@hotmail.com> on 2002/09/17 00:39:06 UTC

Create the MessageResources object

If I have a class that needs to read the values in ApplicationResources.properties but it does not extend the Action class.  What can I do?  I tried this.

ApplicationResources.properties
=======================
testing=HelloWorld


PropertyMessageResourcesFactory mf  = new PropertyMessageResourcesFactory();
MessageResources mr = mf.createResouces("ApplicationResources.properties");
System.out.println(mr.getMessage("testing");

It returns me "null".  What did I do wrong?

Thanks!

Billy Ng


Struts and Java Bean framework

Posted by Vipul Sagare <vi...@yahoo.com>.
Is there any Java Bean framework which can used with Struts framework?
Any ideas/pointers appreciated. Thank you.

Vipul

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Create the MessageResources object

Posted by Billy Ng <ev...@hotmail.com>.
Got it, thanks!

Billy Ng

----- Original Message -----
From: "James Mitchell" <jm...@telocity.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, September 16, 2002 6:57 PM
Subject: RE: Create the MessageResources object


> Problem #1 - Don't put '.properties' when loading a properties file
>
> Problem #2 - This has nothing to do with extending an Action.....
>
> If you have access to the servlet (and you declared the prop file in
> struts-config.xml):
>
>  ((MessageResources)
> servlet.getServletContext().getAttribute(Action.MESSAGES_KEY));
>
> otherwise anywhere in your struts application:
>
>  public class MyClass{
>
>     protected static MessageResources messages =
> MessageResources.getMessageResources
> ("path.to.my.ApplicationResources");
>
>     public doingSomething(...){
>       ...
>       ...
>       String msg = messages.getMessage
>           ("testing");
>       System.out.println(msg);
>       ...
>       ...
>     }
>  }
>
>
> Hope that help you.
>
>
> James Mitchell
> Software Engineer\Struts Evangelist
> Struts-Atlanta, the "Open Minded Developer Network"
> http://www.open-tools.org/struts-atlanta
>
>
>
>
> > -----Original Message-----
> > From: Billy Ng [mailto:evebill8@hotmail.com]
> > Sent: Monday, September 16, 2002 6:39 PM
> > To: Struts Users Mailing List
> > Subject: Create the MessageResources object
> >
> >
> > If I have a class that needs to read the values in
> > ApplicationResources.properties but it does not extend the Action
> > class.  What can I do?  I tried this.
> >
> > ApplicationResources.properties
> > =======================
> > testing=HelloWorld
> >
> >
> > PropertyMessageResourcesFactory mf  = new
> > PropertyMessageResourcesFactory();
> > MessageResources mr =
> > mf.createResouces("ApplicationResources.properties");
> > System.out.println(mr.getMessage("testing");
> >
> > It returns me "null".  What did I do wrong?
> >
> > Thanks!
> >
> > Billy Ng
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Create the MessageResources object

Posted by James Mitchell <jm...@telocity.com>.
Problem #1 - Don't put '.properties' when loading a properties file

Problem #2 - This has nothing to do with extending an Action.....

If you have access to the servlet (and you declared the prop file in
struts-config.xml):

 ((MessageResources)
servlet.getServletContext().getAttribute(Action.MESSAGES_KEY));

otherwise anywhere in your struts application:

 public class MyClass{

    protected static MessageResources messages =
	MessageResources.getMessageResources
	("path.to.my.ApplicationResources");

    public doingSomething(...){
      ...
      ...
      String msg = messages.getMessage
          ("testing");
      System.out.println(msg);
      ...
      ...
    }
 }


Hope that help you.


James Mitchell
Software Engineer\Struts Evangelist
Struts-Atlanta, the "Open Minded Developer Network"
http://www.open-tools.org/struts-atlanta




> -----Original Message-----
> From: Billy Ng [mailto:evebill8@hotmail.com]
> Sent: Monday, September 16, 2002 6:39 PM
> To: Struts Users Mailing List
> Subject: Create the MessageResources object
>
>
> If I have a class that needs to read the values in
> ApplicationResources.properties but it does not extend the Action
> class.  What can I do?  I tried this.
>
> ApplicationResources.properties
> =======================
> testing=HelloWorld
>
>
> PropertyMessageResourcesFactory mf  = new
> PropertyMessageResourcesFactory();
> MessageResources mr =
> mf.createResouces("ApplicationResources.properties");
> System.out.println(mr.getMessage("testing");
>
> It returns me "null".  What did I do wrong?
>
> Thanks!
>
> Billy Ng
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>