You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/07/10 00:44:59 UTC
svn commit: r792736 -
/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
Author: lu4242
Date: Thu Jul 9 22:44:59 2009
New Revision: 792736
URL: http://svn.apache.org/viewvc?rev=792736&view=rev
Log:
MYFACES-2272 Apply changes related to UIInput.validateValue and UIInput.VALIDATE_EMPTY_FIELDS_PARAM_NAME (add isEmpty() method )
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java?rev=792736&r1=792735&r2=792736&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java Thu Jul 9 22:44:59 2009
@@ -19,6 +19,7 @@
package javax.faces.component;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -988,5 +989,50 @@
{
return saveAttachedState(facesContext,_validatorList);
}
- }
+ }
+
+ /**
+ * Check if a value is empty or not. Since we don't know the class of
+ * value we have to check and deal with it properly.
+ *
+ * @since 2.0
+ * @param value
+ * @return
+ */
+ public static boolean isEmpty(Object value)
+ {
+ if (value == null)
+ {
+ return true;
+ }
+ else if (value instanceof String)
+ {
+ if ( ((String)value).length() <= 0 )
+ {
+ return true;
+ }
+ }
+ else if (value instanceof Collection)
+ {
+ if ( ((Collection)value).isEmpty())
+ {
+ return true;
+ }
+ }
+ else if (value.getClass().isArray())
+ {
+ if (java.lang.reflect.Array.getLength(value) <= 0)
+ {
+ return true;
+ }
+ }
+ else if (value instanceof Map)
+ {
+ if ( ((Map)value).isEmpty())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}