mpccolorado
mpccolorado

Reputation: 827

Spring formatters for nulls values

I have a select control in my view and i want to "bind" or "format" the item "Please select an item" to a null value in my backing form object. Is that possible? because i know that making some traditional formatting doesn't work properly. Instead i saw an example of making changes in class GenericConversionService and using that class instead of the original. (unfortunately i can't find it anymore)

This is the exception when i return a null value from my formatter class:

org.springframework.core.convert.ConversionFailedException: Unable to convert value "-1" from type 'java.lang.String' to type 'com.tesisutn.restsoft.dominio.articulo.Marca'; nested exception is java.lang.NullPointerException

Thanks a lot in advance!

Upvotes: 0

Views: 554

Answers (1)

Ralph
Ralph

Reputation: 120811

It looks like your form is sending a -1 to indicate that "Please select an item" is selected.

  • First thing you can try is to send noting. Then the binding (when the form is send to the server) will work, the according command object field will be null.

    <option value="">Please select an item</option>
    
  • If this is no option for you (for example because you use dojo), then you need to implement your own property editor or conversation (Spring 3.0)

Upvotes: 1

Related Questions