Results 1 to 5 of 5

Thread: Newbie Question: setting java.util.date with

  1. #1
    Join Date
    Oct 2004
    Posts
    9

    Default Newbie Question: setting java.util.date with
    I seem to be having a problem with dates, and I can't seem to find the appropriate docs to explain if what I'm trying to do is correct or not.

    I have a bean def such as..

    <bean id="somebean" class="MyBean">
    <property name="someDate">
    <value>10/25/2004</value>
    </property>
    </bean>

    This doesn't seem to work and generates...
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.util.Date]

    Should I be using a custom PropertyEditor here for Dates or am I just using a bad string format for the date? Or am going down a completely wrong path?


  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Should I be using a custom PropertyEditor here for Dates
    Yes .

    Refer to section 3.9 and 3.13 of the reference manual (http://www.springframework.org/docs/reference)

    Alef Arendsen[/url]
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Oct 2004
    Posts
    9

    Default Date Property Editor

    Are there any typical Date Property editors available?

    If i'm understanding the docs correctly PropertyEditors are also used for the the Web data binding to command objects. Is there a best practices example for dealing with dates on forms in an i18n way?

    Thanks, for the help.

    Roy Wells

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    For dates you can actually just use CustomDateEditor, a premade PropertyEditor for dates. The easiest way to register and use it in an application context is via CustomeEditorConfigurer (take a look at the JavaDocs of the latter). When you specify the CustomDateEditor bean, you will just have to provide the date format string.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Oct 2004
    Posts
    9

    Default Thanks

    Thanks Colin,

    I think that clears things up a bit. I've located the javadoc on CustomDateEditor and it's comments on BaseCommandController are helpfull.

    Roy Wells

Similar Threads

  1. java.util.Properties Silly Newbie Question
    By robbiest in forum Container
    Replies: 4
    Last Post: Oct 25th, 2011, 05:49 AM
  2. Newbie transaction isolation question
    By davidhedley in forum Data
    Replies: 4
    Last Post: Sep 12th, 2005, 07:26 PM
  3. Newbie question: How to get spring debug logging on?
    By wangjammer5 in forum Container
    Replies: 2
    Last Post: Jul 15th, 2005, 07:11 AM
  4. Replies: 3
    Last Post: Apr 3rd, 2005, 04:34 PM
  5. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 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
  •