You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Colson <tc...@cisco.com> on 2001/07/06 21:12:11 UTC

Bean Introspection and tag

As per the bean: struts API docs, I've included an "Employee" type object
into the request scope called "emp".

emp can get/set the "mLastName" property using getLastName() and
setLastName()

However - when I try the following

<bean:write name="emp" property="LastName"/>

I'm told that there is no "getter" method
javax.servlet.ServletException: No getter method for property LastName of
bean

If I make the property initial lower case, it works fine:
<bean:write name="emp" property="lastName"/>


The Bean Spec Section 8.8 says this about capitalization:
So for example, “FooBah” becomes “fooBah”
---
So for example, “LastName” becomes “lastName”
I tried adding the accessor "getlastName()" to my Employee class - still
fails.

Property   -> get method    : result
-------------------------------------
"lastName" -> getLastName() : OK
"LastName" -> getLastName() : Fails
"LastName" -> getlastName() : Fails
"LastName" -> get?????()

I searched the archives and read more of the bean spec - but didn't pull up
anything useful on this. :-(

Thanks,
Tim


Re: Bean Introspection and tag

Posted by Martin Cooper <ma...@tumbleweed.com>.
The rule of thumb to follow is that property names should start with a lower
case letter. Otherwise you may come up with property names that cannot be
made to work with getters and setters. This is illustrated in the answers to
your questions below.

> So what IS the getter name for this property - "LastName" ?

There isn't one. If the method was called getLastName, the rules say that,
once 'get' is removed, the first letter should be converted to lower case,
so the property name is 'lastName'. The only exception to converting the
first letter to lower case is when the second letter is also upper case.

> So what IS the getter name for this property - "LASTNAME" => get???

The getter for this is getLASTNAME. Once 'get' is removed, we see that both
the first and second letters are upper case, so the name remains unchanged.

> So what IS the getter name for this property - "lastname" => get???

The getter for this is getLastname. Again, once 'get' is removed, we convert
the first letter to lower case and the property name is 'lastname'.

If you stick to property names that use the same convention as for Java
variables (i.e. the first letter is lower case, and the first letter of
subsequent words is capitalised), then you shouldn't have problems.

I hope this helps clarify.

--
Martin Cooper


----- Original Message -----
From: "Tim Colson" <tc...@cisco.com>
To: <st...@jakarta.apache.org>
Sent: Sunday, July 08, 2001 6:49 AM
Subject: RE: Bean Introspection and <bean:write> tag


> Martin - et. al. -
>
> > What you are seeing is the correct behaviour.
> > Hope this helps.
>
> Thanks for the info - it certainly makes sense, but ultimately you didn't
> answer my question, just re-phrased it. ;-)
>
> "What is the getter name for this property?".
>
> So what IS the getter name for this property - "LastName" ?
>
> BTW - Bean introspection feature or not - it could be a hard sell to get
> designer folk to write "correct cased properties"... especially if they
are
> accustomed to using "LastName" and I can't seem to handle that. Makes the
> developer guy (me) appear not so smart. <grin>
>
> So what IS the getter name for this property - "LASTNAME" => get???
> So what IS the getter name for this property - "lastname" => get???
>
> Thanks! :-)
> Timothy
>
> > ----- Original Message -----
> > From: "Tim Colson" <tc...@cisco.com>
> > To: <st...@jakarta.apache.org>
> > Sent: Friday, July 06, 2001 12:12 PM
> > Subject: Bean Introspection and <bean:write> tag
> >
> >
> > > As per the bean: struts API docs, I've included an "Employee"
> > type object
> > > into the request scope called "emp".
> > >
> > > emp can get/set the "mLastName" property using getLastName() and
> > > setLastName()
> > >
> > > However - when I try the following
> > >
> > > <bean:write name="emp" property="LastName"/>
> > >
> > > I'm told that there is no "getter" method
> > > javax.servlet.ServletException: No getter method for property
> > LastName of
> > > bean
> > >
> > > If I make the property initial lower case, it works fine:
> > > <bean:write name="emp" property="lastName"/>
> > >
> > >
> > > The Bean Spec Section 8.8 says this about capitalization:
> > > So for example, "FooBah" becomes "fooBah"
> > > ---
> > > So for example, "LastName" becomes "lastName"
> > > I tried adding the accessor "getlastName()" to my Employee class -
still
> > > fails.
> > >
> > > Property   -> get method    : result
> > > -------------------------------------
> > > "lastName" -> getLastName() : OK
> > > "LastName" -> getLastName() : Fails
> > > "LastName" -> getlastName() : Fails
> > > "LastName" -> get?????()
> > >
> > > I searched the archives and read more of the bean spec - but didn't
pull
> > up
> > > anything useful on this. :-(
> > >
> > > Thanks,
> > > Tim
> > >
> > >
> >
> >
> >
>
>



RE: Bean Introspection and tag

Posted by Tim Colson <tc...@cisco.com>.
Martin - et. al. -

> What you are seeing is the correct behaviour.
> Hope this helps.

Thanks for the info - it certainly makes sense, but ultimately you didn't
answer my question, just re-phrased it. ;-)

"What is the getter name for this property?".

So what IS the getter name for this property - "LastName" ?

BTW - Bean introspection feature or not - it could be a hard sell to get
designer folk to write "correct cased properties"... especially if they are
accustomed to using "LastName" and I can't seem to handle that. Makes the
developer guy (me) appear not so smart. <grin>

So what IS the getter name for this property - "LASTNAME" => get???
So what IS the getter name for this property - "lastname" => get???

Thanks! :-)
Timothy

> ----- Original Message -----
> From: "Tim Colson" <tc...@cisco.com>
> To: <st...@jakarta.apache.org>
> Sent: Friday, July 06, 2001 12:12 PM
> Subject: Bean Introspection and <bean:write> tag
>
>
> > As per the bean: struts API docs, I've included an "Employee"
> type object
> > into the request scope called "emp".
> >
> > emp can get/set the "mLastName" property using getLastName() and
> > setLastName()
> >
> > However - when I try the following
> >
> > <bean:write name="emp" property="LastName"/>
> >
> > I'm told that there is no "getter" method
> > javax.servlet.ServletException: No getter method for property
> LastName of
> > bean
> >
> > If I make the property initial lower case, it works fine:
> > <bean:write name="emp" property="lastName"/>
> >
> >
> > The Bean Spec Section 8.8 says this about capitalization:
> > So for example, "FooBah" becomes "fooBah"
> > ---
> > So for example, "LastName" becomes "lastName"
> > I tried adding the accessor "getlastName()" to my Employee class - still
> > fails.
> >
> > Property   -> get method    : result
> > -------------------------------------
> > "lastName" -> getLastName() : OK
> > "LastName" -> getLastName() : Fails
> > "LastName" -> getlastName() : Fails
> > "LastName" -> get?????()
> >
> > I searched the archives and read more of the bean spec - but didn't pull
> up
> > anything useful on this. :-(
> >
> > Thanks,
> > Tim
> >
> >
>
>
>


Re: Bean Introspection and tag

Posted by Martin Cooper <ma...@tumbleweed.com>.
What you are seeing is the correct behaviour. I think the piece of the
puzzle you are missing is that, in the part of the JavaBeans spec you are
looking at, it says:

"Thus when we extract a property or event name *from the middle of an
existing Java name*, we
normally convert the first character to lower case."

For example, when extracting the property name from a method named
'getLastName', the first character is converted to lower case, resulting in
the property name 'lastName'.

The thing that is a bit confusing is that the JavaBeans spec talks about how
to obtain the property name from a method (getter or setter) name, whereas
we (at least you and I, anyway!) tend to think of the process the other way
around, as in "what is the getter name for this property?".

Hope this helps.

--
Martin Cooper


----- Original Message -----
From: "Tim Colson" <tc...@cisco.com>
To: <st...@jakarta.apache.org>
Sent: Friday, July 06, 2001 12:12 PM
Subject: Bean Introspection and <bean:write> tag


> As per the bean: struts API docs, I've included an "Employee" type object
> into the request scope called "emp".
>
> emp can get/set the "mLastName" property using getLastName() and
> setLastName()
>
> However - when I try the following
>
> <bean:write name="emp" property="LastName"/>
>
> I'm told that there is no "getter" method
> javax.servlet.ServletException: No getter method for property LastName of
> bean
>
> If I make the property initial lower case, it works fine:
> <bean:write name="emp" property="lastName"/>
>
>
> The Bean Spec Section 8.8 says this about capitalization:
> So for example, "FooBah" becomes "fooBah"
> ---
> So for example, "LastName" becomes "lastName"
> I tried adding the accessor "getlastName()" to my Employee class - still
> fails.
>
> Property   -> get method    : result
> -------------------------------------
> "lastName" -> getLastName() : OK
> "LastName" -> getLastName() : Fails
> "LastName" -> getlastName() : Fails
> "LastName" -> get?????()
>
> I searched the archives and read more of the bean spec - but didn't pull
up
> anything useful on this. :-(
>
> Thanks,
> Tim
>
>