GeeCON Prague 2014*
The moose likes Struts and the fly likes dynavalidator - required, date, String[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "dynavalidator - required, date, String[]" Watch "dynavalidator - required, date, String[]" New topic
Author

dynavalidator - required, date, String[]

Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
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

Joined: Apr 14, 2005
Posts: 354
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 .


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
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

Joined: Apr 14, 2005
Posts: 354
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

Joined: May 16, 2004
Posts: 187
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynavalidator - required, date, String[]