Announcement Announcement Module
No announcement yet.
Binding and getting the result from a form Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding and getting the result from a form

    Hi All,

    So what I am trying to is the following:
    1. Pass an object to a form by using model.addAttribute( "course", course ); where the course is defined as a sessionAttribute for the class using: @SessionAttributes( "course" )
    2. I am using Velocity so in my edit.vm I would like to bind input fields to from this course object. I know you can do it using:
      #springBind( "course.grading" )
      <dl><dd><textarea rows="2" name="grading" cols="100">$!{status.value}</textarea></dd></dl>
    3. When the user submits the form how does this validation business work? and in my edit form function I do something like this:
      @RequestMapping( value = "/edit.html", method = RequestMethod.POST)
      	public String handleForm( 
          		@RequestParam( value = "submit_type", required = true ) String submit_type, 
          		@ModelAttribute( "course" ) Course course,
          		BindingResult bindingResult,
          		SessionStatus status,
          		ModelMap model,
          		HttpServletRequest request, HttpServletResponse response)
      So suppose the user had changed the course.grading variable in the form text box does this get reflected in the course object when it gets passed back to the edit function?

    Question 2: Suppose this course object has a another variable called List <Topic> topics. This is a list of topics. In the form it is displayed as follows:
    1. input field: topic1
    2. input field: topic2
    3. ...
    4. <a...> Add Topic </a> -> Javascript to add more topic input fields

    Now, how do I bind this list and how does adding a new topic using an input field bind a new Topic to the list? if that all makes sense :|

    Any help would be appreciated.

    Last edited by thusi02; Jul 28th, 2008, 05:34 PM. Reason: List didn't come out as a list.