• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp set properly  RSS feed

 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using jsp:setproperty to set the values from the form to the object.

If the fields are empty in the form why are the fields set to null?


Thanks

Anil
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Conversion rules are explained in the JSP spec:

"JSP.1.14.2.1 Conversions from String values".
Table JSP.1-11 Conversions from string values to target type

When target type is a Bean property, the value set will be �null� if the string is empty.
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou

Any suggestions to work around it?

Thanks

Anil
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initialize the member in the bean class.

class MyBean {
String name = "";
...
}

This way, if the text field (called "name" in this example ) is empty,
it will not be set by jsp:setProperty, and the value of the name member will be empty, not null. (not very clear, isn't it ?)
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou,

It worked.



Anil
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!