Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 63969 invoked from network); 4 Aug 2003 21:46:32 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 4 Aug 2003 21:46:32 -0000 Received: (qmail 20924 invoked by uid 97); 4 Aug 2003 21:49:16 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 20917 invoked from network); 4 Aug 2003 21:49:16 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 4 Aug 2003 21:49:16 -0000 Received: (qmail 63721 invoked by uid 500); 4 Aug 2003 21:46:30 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 63698 invoked from network); 4 Aug 2003 21:46:30 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 4 Aug 2003 21:46:30 -0000 Received: (qmail 20911 invoked by uid 50); 4 Aug 2003 21:49:13 -0000 Date: 4 Aug 2003 21:49:13 -0000 Message-ID: <20030804214913.20910.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: commons-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 22121] New: - The "required" validator doesn't work with String[] (multi-selects) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22121 The "required" validator doesn't work with String[] (multi-selects) Summary: The "required" validator doesn't work with String[] (multi-selects) Product: Commons Version: unspecified Platform: All OS/Version: All Status: NEW Severity: Enhancement Priority: Other Component: Validator AssignedTo: commons-dev@jakarta.apache.org ReportedBy: shanebailey@netzero.net The "required" validator doesn't work for String[] i.e. using multi-select input types. I fixed it locally on my machine, though, so here is what I did if you are interested: I changed the org.apache.commons.validator.ValidatorUtil.getValueAsString() method from: public static String getValueAsString(Object bean, String property) { Object value = null; try { value = PropertyUtils.getProperty(bean, property); } catch (Exception e) { log.error(e.getMessage(), e); } return (value != null ? value.toString() : null); } to: public static String getValueAsString(Object bean, String property) { Object value = null; try { value = PropertyUtils.getProperty(bean, property); } catch (Exception e) { log.error(e.getMessage(), e); } //Special case, check if String[] try { String[] valueArray = (String[])value; if(valueArray==null || valueArray.length==0) { value = null; } } catch(ClassCastException cce) { //Then it wasn't a String[] } return (value != null ? value.toString() : null); } I guess, just to be safe the second catch could catch type Exception instead but that is up to you. Anyway, it fixed my validation problem for String[] (multi-selects) and doesn't appear to have broken and validations which worked before. To sum up the problem and requested enhancement, I am using Struts (but it would happen the same way with HTML only) to submit an input of type select and multiple="true" and the validator framework does not detect if nothing is selected in that case. I traced down to the getValueAsString() method as the easiest place to add a fix / change so that the least impact could be made. Above is the code change I made on my local machine to fix "required" type validation for a multi-select input. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org