Announcement Announcement Module
Collapse
No announcement yet.
<spring:bind> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <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
    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

    Comment

    Working...
    X