You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by wt...@apache.org on 2017/06/09 14:59:17 UTC

svn commit: r1798233 - /myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java

Author: wtlucy
Date: Fri Jun  9 14:59:17 2017
New Revision: 1798233

URL: http://svn.apache.org/viewvc?rev=1798233&view=rev
Log:
MYFACES-3525 Add optional fix for INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL required field clear issue

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=1798233&r1=1798232&r2=1798233&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 Fri Jun  9 14:59:17 2017
@@ -91,6 +91,18 @@ public class UIInput extends UIOutput im
     private static final String EMPTY_VALUES_AS_NULL_PARAM_NAME
             = "javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL";
 
+    /** 
+     * When INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is enabled, clear required input fields when empty strings 
+     * are submitted on them
+     *
+     * <p>Note this param is only applicable when INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is enabled.  This 
+     * property addresses an issue wherein values that had previously been populated by the model are re-displayed on 
+     * input fields after empty strings are submitted on those fields.</p>
+     **/
+    @JSFWebConfigParam(defaultValue="false", expectedValues="true, false", since="2.2.13", group="validation")
+    private static final String EMPTY_VALUES_AS_NULL_CLEAR_INPUT_PARAM_NAME
+            = "org.apache.myfaces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL_CLEAR_INPUT";
+
     // our own, cached key
     private static final String MYFACES_EMPTY_VALUES_AS_NULL_PARAM_NAME =
       "org.apache.myfaces.UIInput.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL";
@@ -556,6 +568,26 @@ public class UIInput extends UIOutput im
         return validateEmptyFields;
     }
 
+     /**
+     * Get the value of context parameter
+     * org.apache.myfaces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL_CLEAR_INPUT from the web.xml
+     * 
+     * @return the value of the context parameter
+     */
+    private boolean shouldInterpretEmptyStringSubmittedValuesAsNullClearInput(FacesContext context)
+    {
+        ExternalContext ec = context.getExternalContext();
+       
+        // parses the web.xml to get the
+        // "org.apache.myfaces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL_CLEAR_INPUT" value
+        String param = ec.getInitParameter(EMPTY_VALUES_AS_NULL_CLEAR_INPUT_PARAM_NAME);
+        
+        // evaluate the param
+        Boolean interpretEmptyStringAsNullClearInput = "true".equalsIgnoreCase(param);
+        
+        return interpretEmptyStringAsNullClearInput;
+    }
+
     /**
      * Determine whether the new value is valid, and queue a ValueChangeEvent if necessary.
      * <p>
@@ -597,6 +629,11 @@ public class UIInput extends UIOutput im
             // https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=671
             setSubmittedValue(null);
             submittedValue = null;
+
+            if(shouldInterpretEmptyStringSubmittedValuesAsNullClearInput(context))
+            {
+                setValue(null);
+            }
         }
         // End new JSF 2.0 requirement (INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL)