You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2003/05/21 17:27:25 UTC

[DIGESTER] multiple values for same set-property [WAS: RE: Application Architecture]

Well it looks to me like it says:
"when you see a 'set-property' element thats inside an 'action' element
which is inside an 'action-mappings' element that is inside the
'struts-config' element then call the bean setter method that is named by
that elements 'property' attribute with the value you find in its 'value'
attribute"
Which means that each time it encounters the 'set-property' it will call it.
(nb: I havent verified this behaviour myself (yet ;->))

Were you using an array as the type for your setter in the hopes it would
populate with a whole array at once? I dont think that would work as one
might hope. Id assume it would call it multiple times each time converting
the value to a single element array (assuming its smart enough to do such a
conversion!) - thus leaving you with a single element array corresponding to
the last property set.

The trick would be to do what he does and call add() on a collection in your
setter thus building up the collection over multiple invocations of the
setter.

Easiest way to confirm/invalidate the hypothesis would be to slap a couple
of extra set-property in the nearest conveient action mapping in whatever
app your working on, and shove a System.out.println or log call in the
appropriate setter, fire it up and see what happens. :-)

-----Original Message-----
From: Kruse, Matt [mailto:MKruse@aquent.com]
Sent: Wednesday, 21 May 2003 22:55
To: Struts Users Mailing List
Subject: RE: Application Architecture


> My setter does get called multiple times.
> I use this type of stuff all over the place.  Odd that your's
> doesn't....
> maybe an older version of struts didn't do it?

Which version are you using? I'm on 1.1 rc1, and the set-property definitely
only gets called once, unless I'm doing something really wrong :)

In ConfigRuleSet.java, I see this:

        digester.addSetProperty
            ("struts-config/action-mappings/action/set-property",
             "property", "value");

Is that what you see also? I'm not too familiar with the Digester, so I'm
not sure if there needs to be a slightly different call made to allow for
multiple values of the same property.

Matt Kruse


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


RE: [DIGESTER] multiple values for same set-property [WAS: RE: Application Architecture]

Posted by Andrew Hill <an...@gridnode.com>.
Hmm.
Well Digester uses BeanUtils to do its thing.
Have you given it a shot. It might actually work.
Worth a little experiment :-)

-----Original Message-----
From: Joe Germuska [mailto:Joe@Germuska.com]
Sent: Wednesday, 21 May 2003 23:44
To: Struts Users Mailing List
Subject: Re: [DIGESTER] multiple values for same set-property [WAS: RE:
Application Architecture]


>The trick would be to do what he does and call add() on a collection in
your
>setter thus building up the collection over multiple invocations of the
>setter.

That seems like it's subverting the Beans conventions, though.  If
you have a legitimate indexed property on your bean, you should be
able to do something like this:

<set-property property="foo[0]" value="a" />
<set-property property="foo[1]" value="b" />
<set-property property="foo[2]" value="c" />

which keeps in line with the Bean conventions and makes it totally
clear to anyone else who comes along that the property is indexed.

Joe

--
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"If nature worked that way, the universe would crash all the time."
	--Jaron Lanier

---------------------------------------------------------------------
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: [DIGESTER] multiple values for same set-property [WAS: RE: Application Architecture]

Posted by Joe Germuska <Jo...@Germuska.com>.
>The trick would be to do what he does and call add() on a collection in your
>setter thus building up the collection over multiple invocations of the
>setter.

That seems like it's subverting the Beans conventions, though.  If 
you have a legitimate indexed property on your bean, you should be 
able to do something like this:

<set-property property="foo[0]" value="a" />
<set-property property="foo[1]" value="b" />
<set-property property="foo[2]" value="c" />

which keeps in line with the Bean conventions and makes it totally 
clear to anyone else who comes along that the property is indexed.

Joe

-- 
--
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"If nature worked that way, the universe would crash all the time." 
	--Jaron Lanier

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