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 2008/06/16 17:08:56 UTC

svn commit: r668184 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java

Author: lu4242
Date: Mon Jun 16 08:08:55 2008
New Revision: 668184

URL: http://svn.apache.org/viewvc?rev=668184&view=rev
Log:
TOMAHAWK-750 Raized ClassCastException when Comparing 2 InputDate with validateCompareTo

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java?rev=668184&r1=668183&r2=668184&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/comparetovalidator/CompareToValidator.java Mon Jun 16 08:08:55 2008
@@ -25,8 +25,6 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-import javax.faces.component.UIOutput;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
@@ -276,7 +274,22 @@
         }
         else
         {
-            foreignValue = getConvertedValueNonValid(facesContext, foreignComponent);
+            try 
+            {
+                foreignValue = getConvertedValueNonValid(facesContext, foreignComponent);
+            }
+            catch(ConverterException e)
+            {
+                /*
+                 * If the value cannot be converted this should return,
+                 * because does not have sense compare one
+                 * foreign invalid value with other value.
+                 * this force end the validation but do not continue
+                 * with the next phases, because the converter
+                 * of the foreign component fails and show a validation error.
+                 */
+                return;
+            }
         }
 
         // Don't perform validation if the foreign value is null
@@ -288,36 +301,13 @@
         String operator = getOperatorForString(getOperator());
 
         String alternateOperatorName = getAlternateOperatorName();
-        Object[] args = new Object[5];
-        args[0] = uiComponent.getId();
-        if (uiComponent instanceof UIInput)
-        {
-          UIInput uiInput = (UIInput) uiComponent;
-          args[1] = uiInput.getSubmittedValue();
-        }
-        else
-        {   
-          args[1] = value.toString();
-        }
-        args[2] = (alternateOperatorName == null) ? nameForOperator(operator) : alternateOperatorName;
-        args[3] = foreignComponent.getId();
-        if (foreignComponent instanceof UIOutput)
-        {
-          UIOutput foreignUIOutpout = (UIOutput) foreignComponent;
-          Converter converter = foreignUIOutpout.getConverter();
-          if (converter!=null)
-          {
-            args[4] = converter.getAsString(facesContext, foreignComponent, foreignUIOutpout.getValue());
-          }
-          else
-          {
-            args[4] = (foreignValue == null) ? foreignComponent.getId() : foreignValue.toString();
-          }
-        }
-        else
-        {
-          args[4] = (foreignValue == null) ? foreignComponent.getId() : foreignValue.toString();
-        }
+        Object[] args = {
+                uiComponent.getId(),
+                value.toString(),
+                (alternateOperatorName == null) ? nameForOperator(operator) : alternateOperatorName,
+                foreignComponent.getId(),
+                (foreignValue == null) ? foreignComponent.getId() : foreignValue.toString()
+        };
 
         String message = getMessage();
         if (null == message)  message = COMPARE_TO_MESSAGE_ID;
@@ -528,6 +518,7 @@
     // --------------------- borrowed and modified from UIInput ------------
 
     protected Object getConvertedValueNonValid(FacesContext facesContext, UIComponent component)
+        throws ConverterException
     {
         Object componentValueObject;
         Object submittedValue = ((EditableValueHolder) component).getSubmittedValue();
@@ -537,26 +528,25 @@
         }
         else
         {
-            try
+            Renderer renderer = getRenderer(facesContext, component);
+            if (renderer != null)
             {
-                Renderer renderer = getRenderer(facesContext, component);
-                if (renderer != null)
+                componentValueObject = renderer.getConvertedValue(facesContext, component, submittedValue);
+            }
+            else if (submittedValue instanceof String)
+            {
+                Converter converter = findUIOutputConverter(facesContext, component);
+                if (converter != null)
                 {
-                    componentValueObject = renderer.getConvertedValue(facesContext, component, submittedValue);
+                    componentValueObject = converter.getAsObject(facesContext, component, (String)submittedValue);
                 }
-                else if (submittedValue instanceof String)
+                else
                 {
-                    Converter converter = findUIOutputConverter(facesContext, component);
-                    if (converter != null)
-                    {
-                        componentValueObject = converter.getAsObject(facesContext, component, (String)submittedValue);
-                    }
+                    componentValueObject = submittedValue;
                 }
+            }else{
+                componentValueObject = submittedValue;
             }
-            catch (ConverterException e)
-            {
-            }
-            componentValueObject = submittedValue;
         }
         return componentValueObject;
     }