Announcement Announcement Module
No announcement yet.
Need to redirect object to a form controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need to redirect object to a form controller

    I have this strange situration where I have an file uploaded and parsed to create an object, then I need to show the edit form for that object. In my current setup it works but for some reason the date isn't formatted properly.

    I've looked at my trace messages and found that its not hitting the initBinder method on my form controller. This is how my pages are setup:

    1) getfile.html uploads to upload.html
    2) upload.html is handled by uploadController, returns edit.html view
    3) edit.html posts to edit.html
    4) edit.html is handled by editController

    At step 2, edit.html is not formatting the date properly, this is most likely because its not really using the editController yet.

    I think one alternative is to use the wizard controller except that the editController is going to be used for adding (normally) and editting objects that are already in the database. The upload feature simply provides a way of prepopulating the add form.

    How can I achieve the functionaly I need?


  • #2
    Dates are weird

    Hey friend,

    There is a weird issue with Spring and date formatting where custom formatting needs to be placed on the date object when the initial binding to the form is done.

    Try adding something like this to your form controller:
    * Set up a custom property editor for the application's date format.
    * @param request
    * @param binder
    protected void initBinder(	        
        HttpServletRequest request, 
        ServletRequestDataBinder binder) {
        SimpleDateFormat dateFormat = 
            new SimpleDateFormat("yyyy/MM/dd");
                new CustomDateEditor(dateFormat, true));
    Also ensure your FormController is extending the AbstractFormController which will allow the initBinder() to be present.

    I've found the Spring MVC to be a bit frustrating at first but well worth the effort of sorting out the issues. Just be patient and keep trying to understand.

    I'll watch this thread so let me know how it goes.

    Chris Rosenquest