posted 13 years ago
I believe this is expected behavior - what's happening is that no "name=value" parameter is being sent through the request for that property, so when Spring goes to bind the parameters to the model, that property gets skipped.
One way to fix it is to add a "default" value like you did, so there's always a "name=value" parameter sent for that property.
There are a couple of things on the controller side to address this if you don't like the "default form value" approach -
You can make a custom Converter class for your model object that loads the model and then always clears the potentially-empty property. Register this custom Converter in an @initBinder method in your controller. This works because it clears the value before the request parameters are bound to the model - so if the value is present, it's set, if it's not, it's been cleared.
Instead of always loading the model right away, you can create a brand new instance of your class each time in your controller and have the request values bound to it, then later load the real object you want and "manually" set the properties from the brand new form backing object.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.