Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:setProperty tag not setting property in bean

 
Patrick Noah
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following dynamic form FillDetails.html:

SaveName.jsp:

UserData.java:

If you select abandoned car in the dropdown and fill in values for the make and color the make and color do not get set in the bean! They are null. Why is this? My folder structure is TOMCAT_FOLDER/webapps/email/UserData.java, FillDetails.html, SaveData.jsp. There is also a WEB-INF folder with /classes/user/UserData.class.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used setProperty in that way since about 2001. Submitting a form to a JSP is no longer considered an acceptable practice.

Forms should be submitted to servlet controllers that process the data and delegate activities to the model as necessary. Then, the request is forwarded to a JSP to display the results of the operation.

Have you read this article yet?
 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is that you have named your fields using names starting with an upper-case letter.

Try changing the names of your input controls on the html page: Make-->make and Color-->color and then see if it works.
ie


By the Javabeans specification, properties/variables should start with a lower case letter, and class names should start with an upper case letter.
You need to follow this pattern in order for the java bean to be populated correctly with values coming from the JSP page.
 
Patrick Noah
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Stefan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic