Actually, there's a setter in MyBean (setProp) but no corresponding "prop"
attribute in the XML.  At runtime, the JVM can't find type SomeType, and
it looks like that causes Digester to not ever call setName().  If I
comment out the first 4 lines of the MyBean class (all the
SomeType/setProp stuff), things will work.  Also, if I add type SomeType
to my runtime CLASSPATH, things will work.  Please note that I had an error
in my original post: I never actually do "SomeType p = new SomeType();"
(that line should be "SomeType p;"), that's why there isn't a runtime error.

[EMAIL PROTECTED] wrote:
> Regarding your first point, are you saying "There's a name attribute in the 
> XML, but there's no corresponding setter, so the Digester should flag an 
> error"? If not, I apologise for putting words in your mouth. :-}
> 
> One of the nice things about the Digester is that I can tell it which 
> pieces of the XML I care about, and that's all it calls me about. If I 
> don't care about the value of a certain attribute, I shouldn't need to 
> provide for it. So I consider that a feature rather than a problem.
> 
> --
> Martin Cooper
> 
> At 06:12 PM 3/12/01, Zach Thompson wrote:
> >Hello,
> >
> >I just spent quite a bit of time debugging some code that uses a
> >Digester, and I'd like to share what I found.
> >
> >class MyBean {
> >     SomeType p = new SomeType();
> >     public void setProp(SomeType p) {
> >         this.p = p;
> >     }
> >
> >     String name;
> >     public void setName(String name) {
> >         System.err.println("Setting name...");
> >         this.name = name;
> >     }
> >}
> >
> >...
> >
> ><mybean name="Fred"/>
> >
> >...
> >
> >digester.addSetProperties("mybean");
> >
> >The name property was never being set..
> >
> >The problem was that SomeType was not in my runtime CLASSPATH, so even
> >though setProp() is never called, and hence no runtime error occurs,
> >Digester fails to ever call setName().  Of course, the error here is
> >really mine, but I'd like to at least see Digester give some debugging
> >messages (I had debug detail set to 999).
> >
> >2.  Next I was trying to get the body of a tag and set a bean property
> >with the content:
> >
> ><mybean name="Fred">Some content</mybean>
> >
> >...
> >
> >digester.addSetProperties("mybean");
> >digester.addCallMethod("mybean", "setBody", 0);
> >digester.addSetNext("mybean", "addMyBean");
> >
> >I discovered that at the point addMyBean() is called, setBody() has not
> >been called yet.  I realize that I'm just setting up a Digester
> >here (not actually doing the parsing), so I can imagine that the order of
> >events is not really defined here.  However, it seems like the parsing
> >should generally follow the order that I set up the Digester in.  Am I
> >missing something?
> >
> >Anyway, I'll look at the struts source and see if I can come up with
> >suggestions or patches for struts-dev, but I thought I'd share this info
> >in case it helps anyone.
> >
> >Zach
> 
> 

Reply via email to