Dear AppFuse users,
well, I figured out that the best way is to use Spring's <form:select
...> tag, but I have following error when I try to display my form:
... ERROR [btpool0-1] SelectTag.doStartTag(84) | Invalid property
'type' of bean class [...Comment]: Value of nested property 'type' is
null
org.springframework.beans.NullValueInNestedPathException: Invalid
property 'type' of bean class [...Comment]: Value of nested property
'type' is null
This is my JSP page:
<li>
<appfuse:label styleClass="desc" key="label.type"/>
<form:errors path="type" cssClass="fieldError"/>
<form:select path="type.id">
<form:options items="${CommentTypesList}" itemValue="id"
itemLabel="value"/>
</form:select>
</li>
I've managed to figure out, that error lies in "path" attribute of
<form:select> element. I think that "type.id" is proper value, because
that is what I want to set up in Controller, right? But when I've
changed it to "type" (like in example from Spring reference) the page
was displayed properly, but I got binding errors after form
submission.
What am I doing wrong?
Best regards,
Łukasz Bachman
---------- Forwarded message ----------
From: Łukasz Bachman <[EMAIL PROTECTED]>
Date: 14-12-2007 17:23
Subject: Custom binding of SELECT element
To: [email protected]
Dear AppFuse users,
I was wondering which is the most elegant way of handling HTML's
"SELECT - OPTION" elements? Normally, I was fetching all the form
fields using "request.getParameter()" method, but I find it very
inelegant and it does not help in maintaining code. So, I'm very
curious how are You guys doing it? Let's sketch an example:
Model classes (I got rid of the Hibernate annotations):
public class Comment extends BaseObject {
....
private Type typeOfComment;
....
}
public class Type extends BaseObject {
private Long id;
private String tag; // 'Type' entity will
hold types for different elements
private String value; // The name of the type
....
}
JSP:
( CommentTypesList is of course the list of Types elements)
<select name="type">
<c:forEach var="type" items="${CommentTypesList}">
<option value="<c:out value="${type.id}"/>"><c:out
value="${type.value}"/></option>
</c:forEach>
</select>
And now, the controller:
1) I have overrided "showForm(...)" method which gets
"CommentTypesList" and sends it to the view.
2) If I leave everything as it is in Tutorial's example, I'll get
parsing error because I'm passing types ID.
So I have following questions:
Q1) Which is the best way to avoid that?
Q2) Is there any way to create custom binding rules in pretty elegant manner?
Q3) Do You know of any tags that support displaying "SELECT - OPTION"
elements using custom classes (such as "Type" in my particular
example)?
Best regards,
Łukasz Bachman
P.S. Hope this post is not too long or has inappropriate form. If
that's true - let me know.
P.P.S. I'm using Appfuse 2.0.x, Hibernate + Spring MVC framework