PDA

View Full Version : Commons Validator with Spring MVC


agosti
Apr 27th, 2006, 12:37 PM
Hello,

I'm try to create the same example (Add XDoclet Validator to Person.java )
in page: http://raibledesigns.com/wiki/Wiki.jsp?page=ValidationAndListSpring
But in this example we have only attributes that are not beans, in my case I
have a attribute that is a Bean (Category) and this attribute of Person
class is required.

> My XDocLet code in class person is:
> /**
> * @param category The pais to set.
> * @spring.validator type="required"
> */
> public void setCategory(Category category) {
> this.category = category;
> }
>

The XDocLet code generate in "validation.xml" is (because of the tag
@spring.validator type="required"):
> <form name="person">
> <field property="nome"
> depends="required">
>
> <arg0 key="person.name"/>
> </field>
> <field property="category.name"
> depends="required">
>
> <arg0 key="person.category.name"/>
> </field>
> </form>

But I want to generate this code in validation.xml:
> <form name="person">
> <field property="name"
> depends="required">
>
> <arg0 key="person.name"/>
> </field>

> <field property="category"
> depends="required">
>
> <arg0 key="person.category"/>
> </field>

> </form>


The diference is the field "name" :

> <field property="category.name"
> depends="required">
> <arg0 key="person.category.name"/>
> </field>
to
> <field property="category"
> depends="required">
> <arg0 key="person.category"/>
> </field>

When I execute my jsp page with the "name" of category in my validation.xml
the field in jsp doesn´t appear required.
If I make a manually change in my validation.xml file to:
> <field property="category"
> depends="required">
> <arg0 key="person.category"/>
> </field>

The jsp stay ok with the field category in page jsp person required. But in
this case I need modify manually the file validation.xml all the time.
Would I like to know if exists a way to generate the "validation.xml"
automatically using XDocLet but to generate the code in the format above
with out the field name?
> <field property="category"
> depends="required">
> <arg0 key="person.category"/>
> </field>

My program doesn´t presents erros only the field Category (Bean) in class
Person doesn´t stay required.

Thanks,

Cristiano