Wednesday, April 13, 2011

How is the Spring MVC spring:bind tag working and what are the meanings of status.expression and status.value ?

Let's discuss on the following example:

<spring:bind path="user.userName">
    <input type="text" name="${status.expression}" value="${status.value}"/>
    <span class="fieldError">${status.errorMessage}</span>
</spring:bind>

When this view snippet gets rendered, what do ${status.expression} and ${status.value} get evaluated to? Where do these values come from?

From stackoverflow
  • See this link for an explanation of what the status variables mean.

    • status.expression: the expression that was used to retrieve the bean or property
    • status.value: the actual value of the bean or property (transformed using registered PropertyEditors)
    • status.errorMessages: an array of error messages, resulting from validation

    The status object is evaluated when the binding is done.

    Also have in mind that Spring 2.0 introduced new form tags, which are probable better suited for your needs.

    Koraktor : Thanks for the reminder that the value of `status.value` is generated by the registered PropertyEditor. I implemented a custom editor for setting a property and omitted the `getAsText()` method. This will result in `"null"` strings!

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.