Announcement Announcement Module
No announcement yet.
Property Editors and getAsText() not being called-workaround Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Property Editors and getAsText() not being called-workaround

    I saw a familiar problem being discussed in a few posts where, the getAsText method wasn't being called in the CustomPropertyEditor. I had a similar problem.
    I had a custom property editor written for primitive doubles. In the getAsText() method. I'd retrieve the number and format the number based on locale etc, before sending it to the View, which then would display it as - say - 1,213,99.00 instead of 121399, in the form text field.

    On successful validation of the form , the user would then get a review screen before he submits. My problem was that the double numbers in the review screen would not be formatted because the getAsText method was not being called.
    In the onSubmit method of the controller where i was forwarding the request to the review screen, i was creating the ModelAndView object like this -

    return new ModelAndView(viewName, getCommandName(), o);

    where o is my commandObject.

    Since i realized that the getAsText method was being called everytime the form was being displayed i.e. in case of errors and such, and that the formatting was applied. I looked at the showform method of the AbstractFormController and created my ModelAndView object like it was being done there

    Now i create a ModelAndView object like this -
    return new ModelAndView(viewName, e.getModel());

    where e is the bindException object available in the onsubmit method. The getAsText method is called and i see all my double numbers formatted the way i want in the review screen

    I created the ModelAndView object using the BindException object, just like it was being done in the showForm method of the AbstractFormController.

    The change in workflow (from a GET to a POST) affects the databinding somehow , i'm not sure why and how.

    Now is this how i should do it. It works just fine. Or is there a better way of having the command object recognize the custom property editors?

    Any thoughts?