You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/03/23 14:25:20 UTC

svn commit: r926566 - in /myfaces/core/trunk/api/src: main/java/javax/faces/component/UIInput.java main/java/javax/faces/component/UISelectMany.java test/java/javax/faces/component/UIInputTest.java

Author: jakobk
Date: Tue Mar 23 13:25:20 2010
New Revision: 926566

URL: http://svn.apache.org/viewvc?rev=926566&view=rev
Log:
MYFACES-2615 Conversion errors should add a FacesMessage instead of throwing a FacesException

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
    myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.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=926566&r1=926565&r2=926566&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 Tue Mar 23 13:25:20 2010
@@ -438,10 +438,35 @@ public class UIInput extends UIOutput im
             }
             // End new JSF 2.0 requirement (INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL)
 
-            Object convertedValue = getConvertedValue(context, submittedValue);
-
-            if (!isValid())
+            Object convertedValue;
+            try
+            {
+                convertedValue = getConvertedValue(context, submittedValue);
+            }
+            catch (ConverterException e)
+            {
+                String converterMessage = getConverterMessage();
+                if (converterMessage != null)
+                {
+                    context.addMessage(getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                        converterMessage, converterMessage));
+                }
+                else
+                {
+                    FacesMessage facesMessage = e.getFacesMessage();
+                    if (facesMessage != null)
+                    {
+                        context.addMessage(getClientId(context), facesMessage);
+                    }
+                    else
+                    {
+                        _MessageUtils.addErrorMessage(context, this, CONVERSION_MESSAGE_ID,
+                            new Object[] { _MessageUtils.getLabel(context, this) });
+                    }
+                }
+                setValid(false);
                 return;
+            }
 
             validateValue(context, convertedValue);
 
@@ -479,46 +504,20 @@ public class UIInput extends UIOutput im
      * converter to the submittedValue and return the result.
      * </ul>
      */
-    protected Object getConvertedValue(FacesContext context, Object submittedValue)
+    protected Object getConvertedValue(FacesContext context, Object submittedValue) throws ConverterException
     {
-        try
+        Renderer renderer = getRenderer(context);
+        if (renderer != null)
         {
-            Renderer renderer = getRenderer(context);
-            if (renderer != null)
-            {
-                return renderer.getConvertedValue(context, this, submittedValue);
-            }
-            else if (submittedValue instanceof String)
-            {
-                Converter converter = _SharedRendererUtils.findUIOutputConverter(context, this);
-                if (converter != null)
-                {
-                    return converter.getAsObject(context, this, (String) submittedValue);
-                }
-            }
+            return renderer.getConvertedValue(context, this, submittedValue);
         }
-        catch (ConverterException e)
+        else if (submittedValue instanceof String)
         {
-            String converterMessage = getConverterMessage();
-            if (converterMessage != null)
-            {
-                context.addMessage(getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR,
-                    converterMessage, converterMessage));
-            }
-            else
+            Converter converter = _SharedRendererUtils.findUIOutputConverter(context, this);
+            if (converter != null)
             {
-                FacesMessage facesMessage = e.getFacesMessage();
-                if (facesMessage != null)
-                {
-                    context.addMessage(getClientId(context), facesMessage);
-                }
-                else
-                {
-                    _MessageUtils.addErrorMessage(context, this, CONVERSION_MESSAGE_ID,
-                        new Object[] { _MessageUtils.getLabel(context, this) });
-                }
+                return converter.getAsObject(context, this, (String) submittedValue);
             }
-            setValid(false);
         }
         return submittedValue;
     }

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java?rev=926566&r1=926565&r2=926566&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java Tue Mar 23 13:25:20 2010
@@ -24,7 +24,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 
 import javax.el.ValueExpression;
 import javax.faces.application.FacesMessage;
@@ -37,7 +36,6 @@ import javax.faces.render.Renderer;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperties;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
 
 /**
  * Base class for the various component classes that allow a user to select zero or more options from a set.
@@ -410,37 +408,20 @@ public class UISelectMany extends UIInpu
     }
 
     @Override
-    protected Object getConvertedValue(FacesContext context, Object submittedValue)
+    protected Object getConvertedValue(FacesContext context, Object submittedValue) throws ConverterException
     {
-        try
+        Renderer renderer = getRenderer(context);
+        if (renderer != null)
         {
-            Renderer renderer = getRenderer(context);
-            if (renderer != null)
-            {
-                return renderer.getConvertedValue(context, this, submittedValue);
-            }
-            else if (submittedValue == null)
-            {
-                return null;
-            }
-            else if (submittedValue instanceof String[])
-            {
-                return _SharedRendererUtils.getConvertedUISelectManyValue(context, this, (String[]) submittedValue);
-            }
+            return renderer.getConvertedValue(context, this, submittedValue);
         }
-        catch (ConverterException e)
+        else if (submittedValue == null)
         {
-            FacesMessage facesMessage = e.getFacesMessage();
-            if (facesMessage != null)
-            {
-                context.addMessage(getClientId(context), facesMessage);
-            }
-            else
-            {
-                _MessageUtils.addErrorMessage(context, this, CONVERSION_MESSAGE_ID,
-                    new Object[] { _MessageUtils.getLabel(context, this) });
-            }
-            setValid(false);
+            return null;
+        }
+        else if (submittedValue instanceof String[])
+        {
+            return _SharedRendererUtils.getConvertedUISelectManyValue(context, this, (String[]) submittedValue);
         }
         return submittedValue;
     }

Modified: myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java?rev=926566&r1=926565&r2=926566&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java (original)
+++ myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java Tue Mar 23 13:25:20 2010
@@ -154,7 +154,9 @@ public class UIInputTest extends Abstrac
         expect(mockConverter.getAsObject(facesContext, input, "xxx")).andThrow(new ConverterException());
         replay(mockConverter);
 
-        input.getConvertedValue(facesContext, "xxx");
+        input.setSubmittedValue("xxx");
+        
+        input.validate(facesContext);
         verify(mockConverter);
 
         assertFalse(input.isValid());