Announcement Announcement Module
No announcement yet.
Status object not set if expression absent Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Status object not set if expression absent

    I'm having a problem with the <spring:bind> tag. When I use an object with an expression in the path attribute, the status variable is set correctly in page scope. But when the object is used directly without an expression, the status variable does not seem to be set.

    For example, say I return a ModelAndView from my controller with a User Object in the model with the name "featuredUser".

    If I put the following fragment in the JSP:
          <spring&#58;bind path="featuredUser.firstname">
              The status value is&#58; $&#123;status.value&#125;
          </spring bind>
    It prints out:
    The status value is: Jojo

    Fine and Dandy. However, when I try to use the featured user directly, the status object does not seem to get set. i.e.
          <spring&#58;bind path="featuredUser">
              The status value is&#58; $&#123;status.value&#125;
          </spring bind>
    prints out:
    The status value is:

    Further, if I fake up an accessor called "getMyself()" in my User object, returning "this", and use the following in the JSP:
          <spring&#58;bind path="featuredUser.myself">
              The status value is&#58; $&#123;status.value&#125;
          </spring bind>
    Then it prints out what I want:
    The status value is: [ User: Jojo Manchuri ]

    (the toString() method of my user adds the square brackets and User: prefix).

    My question: why is the status value not set when there is no expression in the path attribute? A quick look in the source code seems to indicate some strangeness in the BindStatus constructor, starting at line 133 of

       Object target = requestContext.getModelObject&#40;beanName&#41;;
       if &#40;this.expression != null && !"*".equals&#40;this.expression&#41; && !this.expression.endsWith&#40;"*"&#41;&#41; &#123;
       	BeanWrapperImpl bw = new BeanWrapperImpl&#40;target&#41;;
       	this.value = bw.getPropertyValue&#40;this.expression&#41;;
    It seems that the value is only set when the expression is non-null AND not equal to * AND not ending in *. In my case, the expression is null, so the (properly retrieved) target variable is just chucked, and I get nothing in the page.

    I'm new to Spring, so I must be missing something. Can anyone help? I'm using version 1.2.