aspose file tools
The moose likes JSP and the fly likes jsp:setProperty and bean property naming convention Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "jsp:setProperty and bean property naming convention" Watch "jsp:setProperty and bean property naming convention" New topic
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
    
  13

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: jsp:setProperty and bean property naming convention
 
Similar Threads
question
setting any object as property in java bean
how to access a bean that has bean created by <jsp:useBean> tag?
usebean is not working with jsp
jsp:setProperty is ignored !