| Author |
jsp:setProperty and bean property naming convention
|
Zlatko Marcok
Greenhorn
Joined: Aug 19, 2009
Posts: 2
|
|
Hello.
I'm working on my SCWCD using the head first book. I'm trying to send a request directly to a JSP. My test is working, but the naming convention of properties seems inconsistent.
Here is my HTML
This is my Direct.jsp
Everything works as expected with the breed property. The methods are getBreed and setBreed so the bean property is breed with a lowercase 'b'. Correct ?
But ID is different. It seems that because the second character is upper case, the convention is no longer to strip off get/set and replace the first character with its lowercase. The convention is just to strip off get and set.
Am I correct ?
My second question is can this property setting be done with anything other than String property types? If my set methods take integers, is there a way to have the conversion done in the jsp?
Thanks for your consideration.
|
 |
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Posts: 1183
|
|
Your setter method needs to be called setID(String id);
Your properties may also be primitive types, the framework does the type conversion for you in case the input is valid.
|
JDBCSupport - An easy to use, light-weight JDBC framework -
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
Things can go easily awry when the bean conventions are violated.
When I have a property for an id (obviously a common need), I always use setId() and getId() so that I can use the normal convention of "id" as the property name.
I don't recommend following the example of "ID".
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sebastian Janisch
Ranch Hand
Joined: Feb 23, 2009
Posts: 1183
|
|
Bear Bibeault wrote:Things can go easily awry when the bean conventions are violated.
When I have a property for an id (obviously a common need), I always use setId() and getId() so that I can use the normal convention of "id" as the property name.
I don't recommend following the example of "ID".
Yes, the convention for variable names says that (except constants) variables start lowercase and then follow the camel case principle.
|
 |
 |
|
|
subject: jsp:setProperty and bean property naming convention
|
|
|