Spring MVC Form tags: Is there a standard way to add “No selection” item?

前端 未结 2 1998
感动是毒
感动是毒 2020-12-30 20:40

There is a select dropdown and I want to add "No selection" item to the list which should give me \'null\' when submitted. I\'m using SimpleFormController derived

相关标签:
2条回答
  • 2020-12-30 21:13

    One option:

    <form:select path="country" title="country" >
         <form:option value="">&nbsp;</form:option>
         <form:options items="${countryList}" />
    </form:select>
    
    0 讨论(0)
  • 2020-12-30 21:38

    I don't think you should need a property editor for this. If the "blank" option is first in the list, and the tag that outputs the list doesn't mark any of them as selected, then the browser should select the first, "blank" one automatically.

    When you submit the form, try and work it so that the "blank" value is bound to your command as a null, which might happen automatically, depending on the type.

    0 讨论(0)
提交回复
热议问题