Announcement Announcement Module
Collapse
No announcement yet.
Use of initBinder ! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of initBinder !

    Hi !

    I've read a lot of topics but I am still confused by how to display a Date!
    I'am succeeding in getting a date from a form (by converting a String whith a special format to a Date) but I can't display my date in a String with the good format.

    Take for example, I have a abstractController where I define my method :
    Code:
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {	 	 
        SimpleDateFormat dateFormat = 
            new SimpleDateFormat("dd/MM/yyyy");
        dateFormat.setLenient(true);
        binder.registerCustomEditor(java.util.Date.class, 
            null, new CustomDateEditor(dateFormat, true));
    }
    Then, I've got a class that use some java.util.Date.

    And I use a controller that extends abstractController and where I redirect to a jsp to display this date.

    Code:
    <c&#58;out value='$&#123;myObj.date&#125;'/>
    But, the displayed date hasn't the wished format :
    Sun Apr 20 00:00:00 CET 4 instead of 20/04/2004 as specified in the SimpleDateFormat of the controller initBinder method.

    How exactly would I do to display : 20/04/2004 !
    Why doesn't it work? What I've forgotten?

    tkx !

  • #2
    To get it displaying properly you need to use c:out within the spring:bind tag. Otherwise use something like:
    Code:
    <fmt&#58;message key="dateFmt" var="pattern"/>
    <fmt&#58;formatDate value="$&#123;myDate&#125;" type="date" pattern="$&#123;pattern&#125;"/>
    And have dateFmt=dd/MM/yyyy in your messages.properties file.

    Comment

    Working...
    X