Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Form Validation - Property Array

 
Mole Moore
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic