Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp set properly  RSS feed

 
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
 
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
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!