File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts Form Validation - Property Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Form Validation - Property Array" Watch "Struts Form Validation - Property Array" New topic

Struts Form Validation - Property Array

Mole Moore

Joined: Apr 03, 2009
Posts: 6
I have ran into a wall on this problem: I have a form that has several properties that are an array of Strings.

In my JSP I am creating controls associated with each element of the array by looping through the array.

I am trying to use validation.xml to check that the fields all have values.

When I try to submit the form and the validation runs I am getting: "Error 500: The field named 'customerCity[]' was not defined for form 'CustomerForm' in the validation configuration. "

If I define each element of the array in validation.xml it works fine.

I am trying to keep the number of customers that a user can enter dynamic so that he/she can choose how many to work per submission. I realize that I can do all of this validation easily in the forms validate method, but I was hoping to take advantage of the client side validation that is provided when using struts validation.

Any help that can be offered is greately apprecited, even if it is simply telling me that this can not be done.

Thanks in advance,
David Newton

Joined: Sep 29, 2008
Posts: 12617

IIRC there's no direct support for doing collection-based validation with a single config in either client-side or XML-based config. You could try using a wildcard for the index, but I doubt it will work (although it's hard for me to keep the frameworks straight anymore).

This might be doable with a custom validator, though, including creating the appropriate JavaScript--may not be worth it, but it's an idea.
Mole Moore

Joined: Apr 03, 2009
Posts: 6
That is what I thought. I will just do the validation server side.

FYI: I tried using wildcards with no success.

Thank you very much for the input!

I agree. Here's the link:
subject: Struts Form Validation - Property Array
It's not a secret anymore!