PDA

View Full Version : spring form tags some funny behaviour


pbsr
Jun 3rd, 2006, 07:04 AM
I am trying to use spring form tags and I am noticing some funny behaviour. May be I am doing some thing wrong. Any pointers will b greatly appreciated.


They don't seem to work without a nested tag being present and I have to repeat the bean names both in nested tags and input tags.

This is the only way I could get it to work
<form:form command="creditcardapp"........>
<spring:nestedPath path="creditcardapp.personalInfo">
<form:input path="personalInfo.title"/>

I would have thought that the it should have worked this way
<form:form command="creditcardapp"........>
<spring:nestedPath path="personalInfo">
<form:input path="title"/>


If I don't use spring form tags and use normal bind expressions it seems to work fine like this
<spring:nestedPath path="creditcardapp.personalInfo">
<spring:bind path="title">
<TD><LABEL for="Title">Title:</LABEL></TD>
<TD><INPUT type="text" name="<c:out value="${status.expression}"/>" size="20" value="<c:out value="${status.value}"/>"></TD>
</spring:bind>

Am I doing something wrong here. Thanks in advance.

gmazza
Jun 3rd, 2006, 07:25 AM
I believe spring:nestedPath is just for 1.2.8, you use it to specify the command (form backing) object so you don't need to keep specifying it in the spring:bind.

So, you would have:
<spring:nestedPath path="loginForm">
<spring:bind path="userid".../>
<spring:bind path="password".../>
</spring:nestedPath>

instead of:
<spring:bind path="loginForm.userid".../>
<spring:bind path="loginForm.password".../>

Also your dot notation with spring:nestedPath (creditcardapp.personalInfo) seems strange. If the form backing/command object defined in your spring-servlet.xml is "personalInfo" -- just use that.

I don't think you should ever be using spring:nestedPath with the 2.0 form:form tag, because you already specify the form backing object with the "command" attribute of form:form.

The link[1] I had given earlier may give a better explanation of things.

Glen

[1] http://www.jroller.com/page/habuma?entry=spring_form_tags

pbsr
Jun 3rd, 2006, 07:53 AM
this looks like a bug .

I am looking at the source of AbstractDataBoundFormElementTag which has something like

private String getNestedPath() {
return (String) this.pageContext.getAttribute(NestedPathTag.NESTED _PATH_VARIABLE_NAME);
}


but when looking at the source of NestedPathTag, the attribute is actually stored in REQUEST_SCOPE and not in PAGE_SCOPE.

I will try to change it and see what happens

pbsr
Jun 3rd, 2006, 09:48 AM
thank you gmazza. What you said was correct. I have not got it working. I don't have to use nested tags. But just looking at the code, it looks like support is there.

pbsr
Jun 3rd, 2006, 09:58 AM
please ignore my first post. My code was wrong. I had a normal spring:bind tag somewhere in the form which was causing all the trouble. Sorry for wasting space.