Results 1 to 2 of 2

Thread: <spring:bind>

  1. #1
    Join Date
    Apr 2008
    Location
    Surabaya
    Posts
    8

    Default <spring:bind>

    Hi all,

    What is the difference between :

    Code:
    <spring:bind path="customer.country">
       <td><input type="text" name="country" value="<c:out value="${status.value}" />" /></td>
    </spring:bind>
    and

    Code:
    <spring:bind path="customer.country">
       <td><input type="text" name="country" value="<c:out value="${customer.country}" />" /></td>
    </spring:bind>
    while in my Controller (extends SimpleFormController) code is :

    Code:
    protected Object formBackingObject(HttpServletRequest request) throws ServletException{
       Customer customer = new Customer();
       return customer;
    }
    
    protected Map referenceData(HttpServletRequest request, Object command, Errors errors) {
       Map myModel = new HashMap();
       Customer cust = new Customer();
       cust.setAUsername("joe");
       myModel.put("customer", cust);
    
       return myModel;
    }
    The both <spring:bind> write the same output, that is "joe". I'd like to know what is the difference between two <spring:bind> code above. I'm afraid there will be a problem on my next learning of Spring Framework. I'm a newb here, and I really appreciate the replies

    Thanks.

  2. #2
    Join Date
    May 2006
    Location
    Rotterdam
    Posts
    58

    Default

    When you use the spring:bind tag, Spring populates a variable called status with value ("joe" in your case). You can also use ${status.errorMessage} if you want to show errors on a per-form-field-basis.

    using the status variable simply made it easy for copy/paste build up of JSPs, plus programmers can read it more easily than when you repeat bound model attribute all over the place.

    If you're using Spring 2.x then you should check out the new Spring form tags. See Craig Walls's blog post for the best explanation:

    http://www.jroller.com/habuma/entry/spring_form_tags

Posting Permissions

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