File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Struts Form Validation - Property Array

Mole Moore
Greenhorn

Joined: Apr 03, 2009
Posts: 6
Hello,
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,
mole
David Newton
Author
Rancher

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
Greenhorn

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!

mole
 
GeeCON Prague 2014
 
subject: Struts Form Validation - Property Array