Results 1 to 4 of 4

Thread: Adding data to model when using showForm()

  1. #1
    Join Date
    Jul 2009
    Posts
    26

    Default Adding data to model when using showForm()

    I have a view which I use for several submit actions. Each action should return the same view (ie, I delete an item from a list and onSubmit gives me the same view with the same command state).

    To achieve this, my onSubmit method returns showForm() as a ModelAndView to "redisplay the form". However, I want to give the user a message if an action went fine or if it didn't (ie - Error deleting an item) but I'm having trouble adding anything to the model that the showForm returns.

  2. #2
    Join Date
    Jul 2009
    Posts
    26

    Default

    Oh dear, I'm slow today. Of course you can return a model with showForm (request, response, errors, model)

  3. #3
    Join Date
    Mar 2010
    Posts
    1

    Default

    Quote Originally Posted by slnm View Post
    Oh dear, I'm slow today. Of course you can return a model with showForm (request, response, errors, model)
    Could you please tell me how to do this as I'm stuck

  4. #4
    Join Date
    Jul 2009
    Posts
    26

    Default

    Sure.

    In your onSubmit method, if you want to redisplay the form, instead of returning a new ModelAndView, create a new Map ie

    Code:
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("someData", "something");
    and return

    HTML Code:
    return showForm(request, response, errors, model);
    Then in the JSP you can simply get the model data the way you normally would, by calling ie

    HTML Code:
    <c:out value="${someData}"/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •