Instead of putting an XDoclet tag on the field, you need to put it on
the setPersonType() method. Also, you only need @spring.validator to
include nested validations - not the specific type.
HTH,
Matt
On 1/8/07, pat79 <[EMAIL PROTECTED]> wrote:
Hi,
i've a problem validating a form with a nested object. let's assume there
are two classes:
public class Person implements java.io.Serializable {
private Integer id;
private String name;
/**
* @spring.validator type="required"
*/
private PersonType personType;
}
public class PersonType implements java.io.Serializable {
private Integer id;
private String name;
/**
* @spring.validator type="required"
*/
private String name;
}
values for PersonType could be "employee" or "director";
the form has two fields which are required: person.name and
person.personType (which is displayed as a dropdown-box):
<test:label styleClass="desc" key="person.name" />
<spring:bind path="person.name">
<span class="fieldError"><c:out
value="${status.errorMessage}"/></span>
<input type="text" name="<c:out value="${status.expression}"/>"
id="<c:out value="${status.expression}"/>" value="<c:out
value="${status.value}"/>"/>
</spring:bind>
<test:label styleClass="desc" key="person.personType"/>
<spring:bind path="person.personType">
<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
<select name="typeId" id="<c:out value="${status.expression}"/>"
class="text medium">
<option value="">Choose one...</option>
<c:forEach items="${availablePersonTypes}" var="type">
<option value="<c:out value="${type.id}" />"
<c:if test="${status.value.id==type.id}">
selected="selected"</c:if>>
<c:out value="${type.name}" />
</option>
</c:forEach>
</select>
</spring:bind>
Additionally i've this methods in my controller:
protected Map referenceData(HttpServletRequest request) throws
ServletException {
Map<String, List<?>> model = new HashMap<String, List<?>>();
model.put(Constants.AVAILABLE_PERSONTYPES, typeMgr
.getPersonTypes(new PersonType()));
return model;
}
protected void onBind(HttpServletRequest request, Object command) throws
ServletException {
Person person = (Person) command;
String typeId = request.getParameter("typeId");
if (typeId != "") {
person.setPersonType(this.typeMgr.getPersonType(typeId));
}
But i don't get an error message if leaving the "personType"-formfield
empty. Does anyone have a hint?
Thanks in advance,
patrick
--
View this message in context:
http://www.nabble.com/Validation-of-nested-objects-tf2939036s2369.html#a8216966
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
http://raibledesigns.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]