Announcement Announcement Module
No announcement yet.
Date format for the whole context Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date format for the whole context

    We have this code in our application Context file:

    <bean id="dateFormatSql" class="java.text.SimpleDateFormat">
       		<constructor-arg><value>dd.MM.yyyy HH&#58;mm</value></constructor-arg>
    	<bean id="customDateEditor" class="org.springframework.beans.propertyeditors.CustomDateEditor">
        		<constructor-arg index="0"><ref local="dateFormatSql"/></constructor-arg>
        		<constructor-arg index="1"><value>true</value></constructor-arg>
    	<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    	   <property name="customEditors">
    	       <entry key="java.util.Date">
    	         <ref bean="customDateEditor"/>
    If we register the customDateEditor via initBinder() the Format of Date Attributes is OK.

    protected void initBinder&#40;HttpServletRequest request, ServletRequestDataBinder binder&#41; &#123;
    	      binder.registerCustomEditor&#40;Date.class, null, customDateEditor&#41;;
    But what can we do to tell the whole Application (all Models) to use this Date format for binding and rendering Dates?

  • #2
    Put it in an abstract parent controller and subclass.

    Speaking of Dates, we're using a custom Date property editor that returns the Date.getTime() (ie a long). Then on the client-side we convert it using JavaScript to a timezone-sensitive date String. When the user changes the date (using, it updates the hidden form parameter containing the long representation of the Date. The property editor then of course converts that long back into a Java Date. A nice way of achieving timezone sensitive Dates using Spring's PropertyEditor approach.


    • #3
      We have no problems with binding or modifying a date, if we register a customEditorConfigurer via initBinder.
      We want to tell the context to render and bind all date attributes of all beans with the format specified in the dateFormatSql bean.