Commons Validator is not capable of making a whole object required,
only properties.  So when you add @spring.validator, it brings in the
properties from that object, not the object itself.

Hope this helps,

Matt

On 1/10/07, pat79 <[EMAIL PROTECTED]> wrote:

Hi Matt,
thanks for the hints.
it works, but i don't understand why the generated code for validation.xml
looks like this:

<form name="person">
     <field property="personType.name" depends="required">
           <arg0 key="person.personType.name"/>
     </field>
</form>

In the Person-Pojo i annotated this:

/**
   * @spring.validator
   */
public void setPersonType() { ... }

So, why validation.xml contains the "name" property, also for <arg>?! this
is bad to handle in the jsp-views.

In my opinion it should look like this:
<form name="person">
     <field property="personType" depends="required">
           <arg0 key="person.personType"/>
     </field>
</form>

best wishes,
Patrick



Matt Raible-3 wrote:
>
> 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]
>
>
>

--
View this message in context: 
http://www.nabble.com/Validation-of-nested-objects-tf2939036s2369.html#a8256044
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]

Reply via email to