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/03/11 00:06:58 UTC

svn commit: r752296 - in /myfaces/core/trunk_1.2.x: api/src/main/java/javax/faces/component/UIInput.java impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java

Author: lu4242
Date: Tue Mar 10 23:06:57 2009
New Revision: 752296

URL: http://svn.apache.org/viewvc?rev=752296&view=rev
Log:
MYFACES-2161 MyFaces-API issue: getValue of UIInput

Modified:
    myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIInput.java
    myfaces/core/trunk_1.2.x/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java

Modified: myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIInput.java?rev=752296&r1=752295&r2=752296&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIInput.java Tue Mar 10 23:06:57 2009
@@ -118,6 +118,20 @@
         setLocalValueSet(true);
         super.setValue(value);
     }
+    
+    /**
+     * Return the current value of this component.
+     * <p>
+     * If a submitted value has been converted but not yet pushed into the
+     * model, then return that locally-cached value (see isLocalValueSet).
+     * <p>
+     * Otherwise, evaluate an EL expression to fetch a value from the model. 
+     */
+    public Object getValue()
+    {
+        if (isLocalValueSet()) return super.getLocalValue();
+        return super.getValue();
+    }
 
     /**
      * Set the "submitted value" of this component from the relevant data in the

Modified: myfaces/core/trunk_1.2.x/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java?rev=752296&r1=752295&r2=752296&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java (original)
+++ myfaces/core/trunk_1.2.x/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlTextRendererTest.java Tue Mar 10 23:06:57 2009
@@ -21,8 +21,15 @@
 import java.io.IOException;
 import java.io.StringWriter;
 
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIViewRoot;
 import javax.faces.component.html.HtmlInputText;
 import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -30,6 +37,7 @@
 import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
 import org.apache.myfaces.test.utils.HtmlRenderedAttr;
 import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.el.MockValueExpression;
 import org.apache.shale.test.mock.MockRenderKitFactory;
 import org.apache.shale.test.mock.MockResponseWriter;
 
@@ -108,4 +116,65 @@
             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
         }
     }
+    
+    public void testWhenSubmittedValueIsNullDefaultShouldDissapearFromRendering() {
+        //See MYFACES-2161 and MYFACES-1549 for details
+        UIViewRoot root = new UIViewRoot();
+        UIForm form = new UIForm();
+        form.setId("formId");
+        
+        form.getChildren().add(inputText);
+        root.getChildren().add(form);
+        
+        Converter converter = new Converter()
+        {
+            public Object getAsObject(FacesContext context,
+                    UIComponent component, String value)
+                    throws ConverterException
+            {
+                if (value == null || "".equals(value))
+                    return null;
+                else
+                    return value;
+            }
+
+            public String getAsString(FacesContext context,
+                    UIComponent component, Object value)
+                    throws ConverterException
+            {
+                if (value == null)
+                    return "";
+                else
+                    return value.toString();
+            }
+        };
+        
+        inputText.setConverter(converter);
+        
+        ValueExpression expression = new MockValueExpression("#{requestScope.someDefaultValueOnBean}",String.class);
+        expression.setValue(facesContext.getELContext(), "defaultValue");
+        inputText.setValueExpression("value", expression);
+        
+        // 1) user enters an empty string in an input-component: ""
+        //Call to setSubmittedValue on HtmlRendererUtils.decodeUIInput(facesContext, component), 
+        //that is called from renderer decode()
+        facesContext.getExternalContext().getRequestParameterMap().put(inputText.getClientId(facesContext), "");
+        
+        inputText.decode(facesContext);
+        
+        // 2) conversion and validation phase: "" --> setValue(null);
+        // isLocalValueSet = true; setSubmittedValue(null);
+        inputText.validate(facesContext);
+        
+        // 3) validation fails in some component on the page --> update model
+        // phase is skipped
+        // No OP
+        
+        // 4) renderer calls getValue(); --> getValue() evaluates the
+        // value-binding, as the local-value is 'null', and I get the
+        // default-value of the bean shown again
+        assertNotSame(expression.getValue(facesContext.getELContext()), inputText.getValue());
+        assertNull(inputText.getValue());
+    }
+
 }