There's probably a few different ways to do it, but you can always fall back to a custom validation method,
@ValidationMethod(when=ValidationState.ALWAYS, on={"event1", "event2"}) public void validateEmails() { if (lotsofemail != null) { for (int i = 0, n = lotsofemail.size(); i <n; ++i) { String email = lotsofemail.get(i); boolean isValid = emailTypeConverter.convert(email); if (isValid) { } else { invalidIndexes.add(i); invalidEmails.add(email); // maybe put these in somewhere else so they can easily correct and resubmit } } } } Something like that, but there still might be a way to do it sticking with the annotations, idk. I hope you're not amassing email addresses to spam people. `_ยด -----Original Message----- From: Derrick Williams [mailto:a...@derrickwilliams.com] Sent: Monday, January 17, 2011 10:03 PM To: stripes-users@lists.sourceforge.net Subject: [Stripes-users] Getting Array Index with Stripes Validations? I've begun using the Stripes @Validation feature and it's been fantastic. It's a lifesaver when Stripes intercepts all the multitudes of input errors and shunts it to my instance of handlesValidationErrors(), using the ValidationErrorHandler interface. My EventHandler doesn't even get called. It's like it was never submitted. It saved me a lot of work. Priceless! Life would be perfect in every way with Stripes Validations except for this one application I'm working on, which for boring reasons needs to handle errors the same way it did before I converted it to Stripes. I'll describe what I'm trying to do, and no doubt there's an infinitely better way to do it. The application has a list of e-mails coming in, being checked by Stripes Validation: @Validate(converter=EmailTypeConverter.class) private List<String> lotsofemail; Our users work their fingers to the bone all day long typing in long lists of e-mail. Invariably they mistype one. No problem, handleValidationErrors() has this under control, right? @Override public Resolution handleValidationErrors(ValidationErrors errors) throws exception{ ...... Almost - the application as it was written really wants to know which index positions in "List<String> lotsofemail" the mistyped e-mails are in, so it can write an error message such as "You typed a badly formed e-mail on lines 4, 5, 9, 12" and so on. The index the error occurred in in 'lotsofemail' doesn't seem to be available (or is it?). To compound my woes, 'lotsofemail' has been scrubbed of invalid e-mails by the time it reaches "handleValidationErrors". It now just contains the correctly formatted e-mails. Not complaining here, in any other situation this would be a GOOD thing, but my goal is to find out which position the incorrect e-mail is in. I can find the actual mistyped e-mail using the 'getFieldValue()' function from the ValidationError collection, but no obvious way to simply search through the original 'lotsofemail' list to deduct its original position. The bad e-mails have been removed, and likewise any information about its original index value is gone. Ok! Not giving up, maybe I can prevent 'lotsofemail' from being scrubbed. I try extending EmailTypeConverter in this Wil E. Coyote sort of way: public class MyEmailTypeConverter extends EmailTypeConverter { EmailTypeConverter therealconverter; public MyEmailTypeConverter(){ therealconverter = new EmailTypeConverter() } public String convert(String input, Class<? extends String> targetType, Collection<ValidationError> errors{ therealconverter.convert(input,targetType,errors); return "Bad Email: "+input; } } My extension *is* working, but not the way I expect. 'lotsofemail' is still scrubbed of bad e-mails, and now it has entries like "Bad Email: g...@email.com". How does it even do that? Spooky! So I hope I've given enough detail about my clumsy hacks to try to get the information I want. Given a List<> of validated input types, how can I tell the index values of that original list containing the invalidated data? Thanks again! -Derrick ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users