Announcement Announcement Module
No announcement yet.
Formatting date when showing form Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formatting date when showing form

    I've already read this thread and this thread, but with no result thus far.

    What happens in my application is that I have a page with a list of users. When you click on one of the user's name, you are redirected to a form, which contains that user's details and where you can edit those details.

    The problem is that the date isn't formatted when the form is displayed. Is there a way of doing this?


    Page with link (form blabla?id=232) --> MyController implements Controller --> page.

    MyController simply retrieves the User object from a backend and adds it to the ModelAndView:

    Map<String, Object> ref = new HashMap<String, Object>();
    ref.put("user", user);
    return new ModelAndView(viewName, ref);
    In my form, I used to have <s:bind path=""><input type="text" value="<fmt:formatDate ..." /></s:bind>. The problem is that when Validator comes across errors, the page is redisplayed, but I get a JSP parsing exception.

    Caused by: javax.servlet.jsp.el.ELException: Cannot find property Editor for class 'class java.util.Date'
    at javelin.jsp.el.ConversionUtils.coerceToObject(Conv
    at javelin.jsp.el.ConversionUtils.coerce(ConversionUt
    at javelin.jsp.el.ExpressionEvaluatorImpl.evaluate(Ex
    at javelin.jsp.el.ExpressionEvaluatorImpl.evaluate(Ex
    When I remove the fmt, the getString method is called and the date isn't formatted. Is there any way to accomplish this? Help would be appreciated .

  • #2
    Ok. I don't know about the threads you have already looked at, but have you tried this simple approach?

     public class MyBindingInitializer implements WebBindingInitializer {
     	public void initBinder(WebDataBinder binder, WebRequest request) {
     		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));


    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
     		<property name="webBindingInitializer">
     			<bean class="org.myproject.MyBindingInitializer" />


    • #3


      • #4
        I've added your suggestion, but when I open my application I get this error:

        Faute: No adapter for handler [package.WelcomeController@b9d7a0]: Does your handler implement a supported interface like Controller?
        WelcomeController doesn't do anything special, just redirecting the user to the first page.

        Any idea what this could be?

        Found out that it's because of the annotations. I don't use annotations in my project, so does anyone know how to perform this type of solution without the annotations?
        Last edited by Bjorn121; Dec 1st, 2008, 06:37 AM.


        • #5
          Are you using 2.5 or greater with annotations? if so you need to annotate a method with @Initbinder then register your binders there.


          • #6
            Sorry just saw your edit regarding annotations. Post your WelcomeController please.


            • #7
              I'm going to revive this thread again. For the moment, our application uses the old skool method <s:bind ...><input value="<fmt ... />" /></s:bind> to show dates in our form.

              I want to remove the s:bind-tags and upgrade it to the form:input tags. So far so good, but my dates are causing problems.

              As you may have read in my first post, this is the flow.

              User clicks on a username and our Controller is triggered (which implements the Controller-interface). Since the Controller interface only holds 1 method, namely handleRequest. So there's not much I can do before I show my page, but to retrieve the objects and put them in the ModelAndView object.

              This is the code:

              public class UserController implements Controller {
                  private UserFacade userFacade;
                  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException {
                      Map<String, Object> ref = new HashMap<String, Object>();
                      User user = userService.getUser(request.getParameter("userid");
                      ref.put("user", user);
                      return new ModelAndView("user", ref);
                  public void setUserFacade(UserFacade userFacade) {
                      this.userFacade = objectiveFacade;
              When this code is executed, a page is shown with a form. That form contains input fields, which can hold a registration date.

              Is it possible to format such a date, with the form:input tag?


              • #8
                No one? It seems rather weird to me that no one (even the staff) knows a solution to this problem.