You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rh...@rdg.boehringer-ingelheim.com on 2001/02/14 16:16:22 UTC

ActionForm property naming conventions

My question is best asked with an example... Why is it that I am unable to
create a property named "nTerminal" for my ActionForm/JSP? This problem
occurs when there is an uppercase letter in the 2nd position of the property
name. If I change the name to "nterminal" or "ntErminal" then things work
just fine. In other words- getNterminal() is recognized by Struts, but
getNTerminal() is invalid and results in a runtime error in the html tag. Is
this a limitation imposed by Javabean conventions or is this a Struts
specific issue? (If you think I am crazy, then perhaps this problem is
specific to WebLogic.)

Thanks,
Bob

Re: ActionForm property naming conventions

Posted by Dzenan Ridjanovic <dz...@fsa.ulaval.ca>.
I have another problem example that I had reported earlier.  I had to change the
property name from eMail to email to get it through.

"Craig R. McClanahan" wrote:

> rhayden@rdg.boehringer-ingelheim.com wrote:
>
> > My question is best asked with an example... Why is it that I am unable to
> > create a property named "nTerminal" for my ActionForm/JSP? This problem
> > occurs when there is an uppercase letter in the 2nd position of the property
> > name. If I change the name to "nterminal" or "ntErminal" then things work
> > just fine. In other words- getNterminal() is recognized by Struts, but
> > getNTerminal() is invalid and results in a runtime error in the html tag. Is
> > this a limitation imposed by Javabean conventions or is this a Struts
> > specific issue? (If you think I am crazy, then perhaps this problem is
> > specific to WebLogic.)
> >
> > Thanks,
> > Bob
>
> Struts uses the introspection capabilities Java Reflection APIs -- in
> particular, it calls java.beans.Introspector.getBeanInfo() -- to figure out the
> names of the getter and setter methods for various properties.  The
> introspector, in turn, enforces the design patterns that are documented in the
> JavaBeans specification.  It is possible that there are some special cases for
> the second letter of a property name being capitalized.
>
> I would have expected "getNTerminal" and "setNTerminal" to work for a property
> named "nTerminal".
>
> Craig


Re: ActionForm property naming conventions

Posted by Martin Cooper <ma...@tumbleweed.com>.
The Introspector.decapitalize() method does indeed have a special case for
where the second letter is capitalized. Here's the offending piece of code
from that method:

 if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
   Character.isUpperCase(name.charAt(0))){
     return name;
 }

So given a method named "getNTerminal", the Introspector will derive a
property name of "NTerminal".

Hope this helps.

--
Martin Cooper
Tumbleweed Communications


----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, February 14, 2001 12:53 PM
Subject: Re: ActionForm property naming conventions


> rhayden@rdg.boehringer-ingelheim.com wrote:
>
> > My question is best asked with an example... Why is it that I am unable
to
> > create a property named "nTerminal" for my ActionForm/JSP? This problem
> > occurs when there is an uppercase letter in the 2nd position of the
property
> > name. If I change the name to "nterminal" or "ntErminal" then things
work
> > just fine. In other words- getNterminal() is recognized by Struts, but
> > getNTerminal() is invalid and results in a runtime error in the html
tag. Is
> > this a limitation imposed by Javabean conventions or is this a Struts
> > specific issue? (If you think I am crazy, then perhaps this problem is
> > specific to WebLogic.)
> >
> > Thanks,
> > Bob
>
> Struts uses the introspection capabilities Java Reflection APIs -- in
> particular, it calls java.beans.Introspector.getBeanInfo() -- to figure
out the
> names of the getter and setter methods for various properties.  The
> introspector, in turn, enforces the design patterns that are documented in
the
> JavaBeans specification.  It is possible that there are some special cases
for
> the second letter of a property name being capitalized.
>
> I would have expected "getNTerminal" and "setNTerminal" to work for a
property
> named "nTerminal".
>
> Craig
>
>



Re: ActionForm property naming conventions

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
rhayden@rdg.boehringer-ingelheim.com wrote:

> My question is best asked with an example... Why is it that I am unable to
> create a property named "nTerminal" for my ActionForm/JSP? This problem
> occurs when there is an uppercase letter in the 2nd position of the property
> name. If I change the name to "nterminal" or "ntErminal" then things work
> just fine. In other words- getNterminal() is recognized by Struts, but
> getNTerminal() is invalid and results in a runtime error in the html tag. Is
> this a limitation imposed by Javabean conventions or is this a Struts
> specific issue? (If you think I am crazy, then perhaps this problem is
> specific to WebLogic.)
>
> Thanks,
> Bob

Struts uses the introspection capabilities Java Reflection APIs -- in
particular, it calls java.beans.Introspector.getBeanInfo() -- to figure out the
names of the getter and setter methods for various properties.  The
introspector, in turn, enforces the design patterns that are documented in the
JavaBeans specification.  It is possible that there are some special cases for
the second letter of a property name being capitalized.

I would have expected "getNTerminal" and "setNTerminal" to work for a property
named "nTerminal".

Craig



Re: ActionForm property naming conventions

Posted by Craig Tataryn <Cr...@msdw.com>.
Basically (and I might be wrong) when you subsequently try access the property,
let's say with an <html:text property="nTerminal"/> tag,  Struts will do a
getNTerminal() on your ActionForm.  The default is to take the property and do
the following:

1) append a "get" prefix to the property
2) change the first letter of the property to uppercase
3) call that method on the form bean.

So for instance, it's prefixing your nTerminal property and mangaling it like
so:

getNTerminal()

Like I said, I haven't looked at the code, but this is how I understand the
process.

Craig.

rhayden@rdg.boehringer-ingelheim.com wrote:

> My question is best asked with an example... Why is it that I am unable to
> create a property named "nTerminal" for my ActionForm/JSP? This problem
> occurs when there is an uppercase letter in the 2nd position of the property
> name. If I change the name to "nterminal" or "ntErminal" then things work
> just fine. In other words- getNterminal() is recognized by Struts, but
> getNTerminal() is invalid and results in a runtime error in the html tag. Is
> this a limitation imposed by Javabean conventions or is this a Struts
> specific issue? (If you think I am crazy, then perhaps this problem is
> specific to WebLogic.)
>
> Thanks,
> Bob

--
I've been trying to change the world for years, but they just won't give me the
source code....