Results 1 to 3 of 3

Thread: Date format for the whole context

  1. #1
    Join Date
    Nov 2004
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    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.

  3. #3
    Join Date
    Nov 2004
    Posts
    2

    Default

    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.

Similar Threads

  1. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Date format using JDBC Template
    By macmeureg in forum Data
    Replies: 5
    Last Post: Jun 29th, 2005, 10:18 AM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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