struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Overloaded Setters in Form
Date Tue, 24 Dec 2002 18:26:23 GMT


On Tue, 24 Dec 2002, Carl Fyffe wrote:

> Date: Tue, 24 Dec 2002 13:12:48 -0500
> From: Carl Fyffe <struts@sixty4bit.com>
> Reply-To: Struts Developers List <struts-dev@jakarta.apache.org>
> To: 'Struts Developers List' <struts-dev@jakarta.apache.org>
> Subject: RE: Overloaded Setters in Form
>
> Edgar does have a point, the spec doesn't say beans *bad joke* about
> overloading.

It actually does, but by omission, not comission :-).  See below.

>  I gave it another go after reading (AGAIN) Craig's first
> post on this topic (12/14/2002) and this time, instead of using a null
> getter, I provided a getter for the overloaded setter.  Still does not
> work.  Introspector only returns one PropertyDescriptor for the
> property.  Edgar and Craig both lead me to believe that this is
> possible, but I am starting to think that I am trying to put a square
> peg in a round hole.
>

Please give up now :-).  Consider the fact that trying to create
overloaded setters will actually compile:

    public void setProp(Foo foo) { ... }
    public void setProp(Bar bar) { ... }

(even though Java won't recognize "prop" as a valid JavaBeans property),
but trying to create overloaded getters will give you a compile error:

    public Foo getProp() { ... }
    public Bar getProp() { ... }

The bottom line is that the design pattern for JavaBeans properties talks
about a getter *method* (singular) and/or a setter *method* (singular)
with no mention of *methods* (plural) in either scenario.  This is also
reflected in the introspection APIs -- consider for example the following
methods on java.beans.PropertyDescriptor (which is what beanutils is using
under the covers to call the getter and setter dynamically):

    public Method getReadMethod();
    public Method getWriteMethod();

Even assuming you tried to create a write-only property with just the two
set methods, there is no reaonable rule for Java to choose which one to
return via getWriteMethod().  So, the language punts and decides that you
have not defined a property at all.

> Edgar: Would you be willing to share some of your implementation
> details?
>
> Architectural Gurus: The problem I am trying to solve is that I have a
> data source that returns Strings only (xml file), should I create Beans
> specifically for that data source and then convert over to my Form?
>

ActionForm beans should generally use String properties for anything that
is going to be updatable (by the user) via a text input field.  What kind
of conversion do you need to do?  (Or, more broadly, why are you trying to
use overloaded property methods in the first place?)

> Thanks for all of your help,
>
> Carl

Craig


--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message