Announcement Announcement Module
Collapse
No announcement yet.
binding to java.sql.Timestamp (custom editor) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding to java.sql.Timestamp (custom editor)

    Hello, I've searched the forum and cannot find a satisfactory answer.

    I have an abstractCommandController with validator and command object. The comman object holds to fields java.sql.Timestamp.

    I simply want to allow the user to enter two dates in the form dd/MM/yyyy and bind this into the command object.

    I have tried registrating custom editors in the initBinder method

    protected void initBinder(HttpServletRequest req, ServletRequestDataBinder binder) throws Exception
    {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(java.sql.Date.class, new CustomDateEditor(dateFormat, true));
    binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(dateFormat, true));
    binder.registerCustomEditor(java.sql.Timestamp.cla ss, new CustomDateEditor(dateFormat, true));
    }


    Out of desperation I've registered all 3 Date type classes since I keep getting the error message

    javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${status.value}": Attempt to convert String "23/11/2004" to type "java.util.Date", but there is no PropertyEditor for that type (null)


    I am totally missing something? I cannot find any good documentation in this area. I'll be quite happy to read some if someone directs me please.

    The error is occurring when the jsp is rendered using

    <spring:bind path="command.effFromDate">
    <td>From Date</td><td><input type="text" name="<c:out value="${status.expression}"/>" value="<fmt:formatDate value="${status.value}" pattern="dd/MM/yyyy"/>"/></td>
    </spring:bind>
    <td></td>
    <spring:bind path="command.effToDate">
    <td>To Date</td><td><input type="text" name="<c:out value="${status.expression}"/>" value="<fmt:formatDate value="${status.value}" pattern="dd/MM/yyyy"/>"/></td>
    </spring:bind>

    Any help would be appreciated. Thanks.

  • #2
    don't use the <fmt:formatDate> tag when using Spring's property editors. Spring does the formatting for you!!

    status.value results in a String and <fmt:formatDate value="XXXX"/> expects a Date objects, that's what causing the error...

    So simply changing it to <c:out value="${status.value}"/> will do...

    regards,
    Alef

    Comment


    • #3
      Thankyou. It is now making sense.

      Comment

      Working...
      X