Announcement Announcement Module
Collapse
No announcement yet.
Newbie Question: setting java.util.date with Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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]

    Comment


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

      Comment


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

        Comment


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

          Comment

          Working...
          X