Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynavalidator - required, date, String[]

 
Swamy Nathan
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a dynavalidator form with a field of type java.lang.String[]

I needed to set a dependency of type required & date on each row.

How do I do this without modifying / extending the commons beans validator framework ?

I am using the iterate logic tag and displaying 3 textboxes.

My dyna form bean has a size attribute of 3.

I think the problem is that the textboxes get name attribute (in rendered html)- dyanformfield[0].dyanformfield, dyanformfield[1].dyanformfield etc but the form field is not a bean just a string in a string array.
[ September 24, 2005: Message edited by: Swamy Nathan ]
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use normal validation set up without modifying anything by using the indexListProperty attribute of each field. here's a good example: http://www.strutskickstart.com/IndexedPropertiesandValidation.ppt#18 .
 
Swamy Nathan
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked.
But I have another problem.

Lets say I did not fill up all 3 rows.

It just indicates the problem for the first row in my jsp.

When I do a system.out on the action errors object i find it contains only 1 error for strArray[0].strArray and nothing for [1], [2]
[ September 24, 2005: Message edited by: Swamy Nathan ]
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ValidatorPlugIn class has a stopOnFirstError attribute that can be set (i dont know the exact syntax). i believe the default is true (http://struts.apache.org/api/org/apache/struts/validator/ValidatorPlugIn.html).

the danger of having ALL messages displayed is that you can get all of them displayed (3 per each row that is missing the values repeating, along with other fields) that will no doubt be user-unfriendly. the key is to have a UI that explains to the user that 3 fields are required (*star, bold, whatever). if they are not understanding this, then it's the user's problem.
 
Swamy Nathan
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stopOnFirstError is about Javascript I think.

I was looking at a scenario where I have a a string array defined as a field in a dynavalidator form with a size of say 3.

In my jsp I use logic:iterate and show 3 textboxes.
I show the error messages for each text box indexed field also.

Unfortunately it shows only the errors encountered in the first problematic indexed field. Subsequent indexed fields are not being validated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic