Results 1 to 2 of 2

Thread: How to allow null date in Spring 3 MVC

  1. #1
    Join Date
    Jan 2008
    Location
    Pisa, Italy
    Posts
    23

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •