Announcement Announcement Module
Collapse
No announcement yet.
How to allow null date in Spring 3 MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to allow null date in Spring 3 MVC

    I've defined a global formatter for date bindings:

    Code:
    <annotation-driven conversion-service="conversionService" />
    
    <beans:bean id="conversionService"
    	class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    	<beans:property name="converters">
    		<beans:list>
    			...
    		</beans:list>
    	</beans:property>
    	<beans:property name="formatters">
    		<beans:set>
    			<beans:bean id="dateFormatter"
    				class="org.springframework.format.datetime.DateFormatter">
    				<beans:constructor-arg><beans:value>dd/MM/yyyy</beans:value></beans:constructor-arg>
    			</beans:bean>
    	</beans:set>
    	</beans:property>
    </beans:bean>
    This is working fine but now I also need that a particular date field can be left blank. How can I configure the formatter (or this very field) to accept null value?

    Thanks!

  • #2
    The formatter doesn't allow null/empty values and cannot be configured for it. The older CustomDateEditor has support for that, so you might want to switch (if that is possible).

    If it is for a single field (assuming you use it in a web environment) implement a @InitBinder method which registers a editor/formatter for this specific field.

    Comment

    Working...
    X