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

  • Date format for the whole context

    We have this code in our application Context file:

    Code:
    	
    <bean id="dateFormatSql" class="java.text.SimpleDateFormat">
       		<constructor-arg><value>dd.MM.yyyy HH&#58;mm</value></constructor-arg>
    	</bean>
    	
    	<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>
    
    	<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    	   <property name="customEditors">
    	     <map>
    	       <entry key="java.util.Date">
    	         <ref bean="customDateEditor"/>
    	       </entry>
    	     </map>
    	   </property>
    	 </bean>
    If we register the customDateEditor via initBinder() the Format of Date Attributes is OK.

    Code:
    protected void initBinder&#40;HttpServletRequest request, ServletRequestDataBinder binder&#41; &#123;
    	      binder.registerCustomEditor&#40;Date.class, null, customDateEditor&#41;;
    &#125;
    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 http://www.dynarch.com/projects/calendar/), 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.

    Comment


    • #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.

      Comment

      Working...
      X