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:
It prints out:Code:<spring:bind path="featuredUser.firstname"> The status value is: ${status.value} </spring bind>
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.
prints out:Code:<spring:bind path="featuredUser"> The status value is: ${status.value} </spring bind>
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:
Then it prints out what I want:Code:<spring:bind path="featuredUser.myself"> The status value is: ${status.value} </spring bind>
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 BindStatus.java
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.Code:Object target = requestContext.getModelObject(beanName); ... if (this.expression != null && !"*".equals(this.expression) && !this.expression.endsWith("*")) { BeanWrapperImpl bw = new BeanWrapperImpl(target); this.value = bw.getPropertyValue(this.expression); }
I'm new to Spring, so I must be missing something. Can anyone help? I'm using version 1.2.
Thanks![]()


Reply With Quote