Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:setProperty and bean property naming convention  RSS feed

 
Zlatko Marcok
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!