commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (VALIDATOR-149) required validator doesn't work with String[] (multi-selects)
Date Wed, 19 Jul 2006 13:52:16 GMT
     [ http://issues.apache.org/jira/browse/VALIDATOR-149?page=all ]

Niall Pemberton resolved VALIDATOR-149.
---------------------------------------

    Fix Version/s: 1.1.0 (alpha)
       Resolution: Fixed

Re-openned and the set to "Resolved Fixed" again to correct "resolution" which was lost in
Bugzilla --> JIRA conversion

> required validator doesn't work with String[] (multi-selects)
> -------------------------------------------------------------
>
>                 Key: VALIDATOR-149
>                 URL: http://issues.apache.org/jira/browse/VALIDATOR-149
>             Project: Commons Validator
>          Issue Type: Improvement
>         Environment: Operating System: All
> Platform: All
>            Reporter: shane
>            Priority: Minor
>             Fix For: 1.1.0 (alpha)
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message