You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/03/01 14:40:01 UTC

Get MessageResource in ActionForm

Subject: Get MessageResource in ActionForm
From: "Dirk Breitenbach" <br...@danet.de>
 ===
Hi,

can someone give me a hint, how i can access MessageResources (From
ApplicationResources.properties) within a Subclass of ActionForm???

My prpoblem is, the ActionForm does not know anything about the
ActionServlet, and so I have no Chance to get the Messages within
ActionForm.

I tried this:
servlet.getMessageResources().getMessage("STRING_TO_LOOK_UP");

But "servlet" and "getServlet" returns null.

How can I solve this Problem???

Dirk



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


Re: Digester and inheritance

Posted by Stacy Weng <st...@yahoo.com>.
the beaninfo is all in the parent class - Component...

--Stacy
  ----- Original Message ----- 
  From: dIon Gillard 
  To: Struts Users Mailing List 
  Sent: Saturday, March 02, 2002 8:06 PM
  Subject: Re: Digester and inheritance


  Stacy Weng wrote:

  >I have a parent class called Component, and several child classes extending from it.   All the common get/set methods are defined in Component.  So, after each child is getting created from addObjectCreate() method, I call addSetProperties() method to initialize their values (values are from the xml file), however, digester can't find the set methods from the child class, cause they're defined in the parent class (Component).  The temporary solution I had was defining those set methods in the child classes, and have them call the super methods.  But that seems to defeat the whole purpose of inheritance.  Here's an example with the problem:
  >
  >public class Component {
  >    public String name = null;
  >    public void setName(String name) {
  >        this.name=name;
  >    }
  >    public void getname() {
  >        return this.name;
  >    }
  >}
  >
  >public class ChildClass extend Component {
  >    //Other methods that differ from parent class
  >}
  >
  Do you have any beaninfo classes coded/generated for ChildClass?

  >
  >for the digester rules:
  >
  >digester.addObjectCreate("ChildClassPattern", "some.package.ChildClass");
  >digester.addSetProperties("ChildClassPattern");
  >
  >so, as it gets to addSetProperties(), it doesn't see any of the get/set methods in ChildClass, and yet, it doesn't know to look its parent class, Component.
  >
  >I hope I'm able to get my problem across.  Thanks again for taking the time to respond.
  >
  >--Stacy
  >
  -- 
  dIon Gillard, Multitask Consulting
  http://adslgateway.multitask.com.au/developers




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

Re: Digester and inheritance

Posted by dIon Gillard <di...@multitask.com.au>.
Stacy Weng wrote:

>I have a parent class called Component, and several child classes extending from it.   All the common get/set methods are defined in Component.  So, after each child is getting created from addObjectCreate() method, I call addSetProperties() method to initialize their values (values are from the xml file), however, digester can't find the set methods from the child class, cause they're defined in the parent class (Component).  The temporary solution I had was defining those set methods in the child classes, and have them call the super methods.  But that seems to defeat the whole purpose of inheritance.  Here's an example with the problem:
>
>public class Component {
>    public String name = null;
>    public void setName(String name) {
>        this.name=name;
>    }
>    public void getname() {
>        return this.name;
>    }
>}
>
>public class ChildClass extend Component {
>    //Other methods that differ from parent class
>}
>
Do you have any beaninfo classes coded/generated for ChildClass?

>
>for the digester rules:
>
>digester.addObjectCreate("ChildClassPattern", "some.package.ChildClass");
>digester.addSetProperties("ChildClassPattern");
>
>so, as it gets to addSetProperties(), it doesn't see any of the get/set methods in ChildClass, and yet, it doesn't know to look its parent class, Component.
>
>I hope I'm able to get my problem across.  Thanks again for taking the time to respond.
>
>--Stacy
>
-- 
dIon Gillard, Multitask Consulting
http://adslgateway.multitask.com.au/developers




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


Re: Digester and inheritance

Posted by Stacy Weng <st...@yahoo.com>.
I have a parent class called Component, and several child classes extending from it.   All the common get/set methods are defined in Component.  So, after each child is getting created from addObjectCreate() method, I call addSetProperties() method to initialize their values (values are from the xml file), however, digester can't find the set methods from the child class, cause they're defined in the parent class (Component).  The temporary solution I had was defining those set methods in the child classes, and have them call the super methods.  But that seems to defeat the whole purpose of inheritance.  Here's an example with the problem:

public class Component {
    public String name = null;
    public void setName(String name) {
        this.name=name;
    }
    public void getname() {
        return this.name;
    }
}

public class ChildClass extend Component {
    //Other methods that differ from parent class
}

for the digester rules:

digester.addObjectCreate("ChildClassPattern", "some.package.ChildClass");
digester.addSetProperties("ChildClassPattern");

so, as it gets to addSetProperties(), it doesn't see any of the get/set methods in ChildClass, and yet, it doesn't know to look its parent class, Component.

I hope I'm able to get my problem across.  Thanks again for taking the time to respond.

--Stacy



----- Original Message ----- 
  From: Fernando Esteban Barril Otero 
  To: Struts Users Mailing List 
  Sent: Friday, March 01, 2002 1:48 PM
  Subject: Re: Digester and inheritance


  I'm using digester and inheritance without problems. What kind
  of exception are you getting?

  Fernando

  ----- Original Message -----
  From: "Stacy Weng" <st...@yahoo.com>
  To: "Struts Users Mailing List" <st...@jakarta.apache.org>
  Sent: Friday, March 01, 2002 1:20 PM
  Subject: Digester and inheritance


  Has anyone encountered problems with inheritance using Digester?  It seems
  to me that the addSetProperties() does not when its object is inherited from
  a parent class...hence it assumes the get/set methods aren't defined, when
  they are actually defined in its parent class.  I've looked into the source,
  and it seems that the getMethod call that digester uses does not handle
  parent methods.  Is there a patch out there for inheritance with digester?

  Once again, thanks again in advance for any input.  It is greatly
  appreciated.  =)

  --Stacy



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


Re: Digester and inheritance

Posted by Fernando Esteban Barril Otero <fe...@visionnaire.com.br>.
I'm using digester and inheritance without problems. What kind
of exception are you getting?

Fernando

----- Original Message -----
From: "Stacy Weng" <st...@yahoo.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, March 01, 2002 1:20 PM
Subject: Digester and inheritance


Has anyone encountered problems with inheritance using Digester?  It seems
to me that the addSetProperties() does not when its object is inherited from
a parent class...hence it assumes the get/set methods aren't defined, when
they are actually defined in its parent class.  I've looked into the source,
and it seems that the getMethod call that digester uses does not handle
parent methods.  Is there a patch out there for inheritance with digester?

Once again, thanks again in advance for any input.  It is greatly
appreciated.  =)

--Stacy



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


Digester and inheritance

Posted by Stacy Weng <st...@yahoo.com>.
Has anyone encountered problems with inheritance using Digester?  It seems to me that the addSetProperties() does not when its object is inherited from a parent class...hence it assumes the get/set methods aren't defined, when they are actually defined in its parent class.  I've looked into the source, and it seems that the getMethod call that digester uses does not handle parent methods.  Is there a patch out there for inheritance with digester?

Once again, thanks again in advance for any input.  It is greatly appreciated.  =)

--Stacy

RE: Get MessageResource in ActionForm

Posted by "Juan Alvarado (Struts List)" <ju...@manduca.com>.
I do the following in the perform method of my action classes:

//Load our message resources
MessageResources messages    = getResources();
String message = messages.getMessage("messageString");

This works for me. I hope it helps!!!

**********************************************
Juan Alvarado
Internet Developer -- Manduca Management
(786)552-0504
jalvarado@manduca.com
AOL Instant Messenger: juan2000@aol.com

-----Original Message-----
From: Bruce.Geerdes@sun.com [mailto:Bruce.Geerdes@sun.com]
Sent: Friday, March 01, 2002 11:08 AM
To: Struts Users Mailing List
Subject: Re: Get MessageResource in ActionForm


"Struts Newsgroup (@Basebeans.com)" wrote:

> can someone give me a hint, how i can access MessageResources (From
> ApplicationResources.properties) within a Subclass of ActionForm???
>
> My prpoblem is, the ActionForm does not know anything about the
> ActionServlet, and so I have no Chance to get the Messages within
> ActionForm.
>
> I tried this:
> servlet.getMessageResources().getMessage("STRING_TO_LOOK_UP");
>
> But "servlet" and "getServlet" returns null.

Are you using the nightly build?  One used to be able to use
getServlet().getResources() from an ActionForm, but
ActionServlet.getResources
has been deprecated.  Last time I tried it, it didn't seem to be working any
longer either.

Currently I'm getting the resources by calling
"request.getAttribute(Action.MESSAGES_KEY)".

Bruce


--
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: Get MessageResource in ActionForm

Posted by Bruce Geerdes <br...@sun.com>.
"Struts Newsgroup (@Basebeans.com)" wrote:

> can someone give me a hint, how i can access MessageResources (From
> ApplicationResources.properties) within a Subclass of ActionForm???
>
> My prpoblem is, the ActionForm does not know anything about the
> ActionServlet, and so I have no Chance to get the Messages within
> ActionForm.
>
> I tried this:
> servlet.getMessageResources().getMessage("STRING_TO_LOOK_UP");
>
> But "servlet" and "getServlet" returns null.

Are you using the nightly build?  One used to be able to use
getServlet().getResources() from an ActionForm, but ActionServlet.getResources
has been deprecated.  Last time I tried it, it didn't seem to be working any
longer either.

Currently I'm getting the resources by calling
"request.getAttribute(Action.MESSAGES_KEY)".

Bruce


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