You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2007/03/15 23:29:13 UTC
svn commit: r518788 - in /myfaces/core/branches/jsf12/api/src:
main/java/javax/faces/component/UIComponent.java
test/java/javax/faces/component/UIComponentTest.java
Author: mbr
Date: Thu Mar 15 15:29:10 2007
New Revision: 518788
URL: http://svn.apache.org/viewvc?view=rev&rev=518788
Log:
better support for legacy code which does not implement UIComponentBase
+ Tests
Modified:
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponent.java
myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIComponentTest.java
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponent.java?view=diff&rev=518788&r1=518787&r2=518788
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponent.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/component/UIComponent.java Thu Mar 15 15:29:10 2007
@@ -15,17 +15,18 @@
*/
package javax.faces.component;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
*
@@ -49,12 +50,32 @@
*/
public abstract javax.faces.el.ValueBinding getValueBinding(java.lang.String name);
- public ValueExpression getValueExpression(String name) {
- if (name == null) throw new NullPointerException("name can not be null");
-
- if (bindings == null) return null;
-
- return bindings.get(name);
+ public ValueExpression getValueExpression(String name)
+ {
+ if (name == null)
+ throw new NullPointerException("name can not be null");
+
+ if (bindings == null)
+ {
+ if (!(this instanceof UIComponentBase))
+ {
+ // if the component does not inherit from UIComponentBase and don't implements JSF 1.2 or later
+ ValueBinding vb = getValueBinding(name);
+ if (vb != null)
+ {
+ bindings = new HashMap<String, ValueExpression>();
+ ValueExpression ve = new _ValueBindingToValueExpression(vb);
+ bindings.put(name, ve);
+ return ve;
+ }
+ }
+ }
+ else
+ {
+ return bindings.get(name);
+ }
+
+ return null;
}
/**
Modified: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIComponentTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIComponentTest.java?view=diff&rev=518788&r1=518787&r2=518788
==============================================================================
--- myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIComponentTest.java (original)
+++ myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIComponentTest.java Thu Mar 15 15:29:10 2007
@@ -15,7 +15,7 @@
*/
package javax.faces.component;
-import static org.apache.myfaces.Assert.*;
+import static org.apache.myfaces.Assert.assertException;
import static org.easymock.EasyMock.*;
import java.lang.reflect.Method;
@@ -31,6 +31,7 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -68,7 +69,7 @@
@Override
protected void setUp() throws Exception
{
- _mocksControl = EasyMock.createControl();
+ _mocksControl = EasyMock.createNiceControl();
_facesContext = _mocksControl.createMock(FacesContext.class);
}
}
@@ -244,6 +245,7 @@
Class<UIComponent> clazz = UIComponent.class;
mockedMethods.add(clazz.getDeclaredMethod("getAttributes", null));
mockedMethods.add(clazz.getDeclaredMethod("getFacesContext", null));
+ mockedMethods.add(clazz.getDeclaredMethod("getValueBinding", new Class[] { String.class }));
_testimpl = _mocksControl.createMock(clazz, mockedMethods.toArray(new Method[mockedMethods.size()]));
_expression = _mocksControl.createMock(ValueExpression.class);
@@ -251,7 +253,7 @@
_mocksControl.checkOrder(true);
}
- public void testSetValueExpressionArguments() throws Exception
+ public void testValueExpressionArguments() throws Exception
{
assertException(NullPointerException.class, new SetValueExpressionTestRunner(_testimpl, null, _expression));
assertException(IllegalArgumentException.class, new SetValueExpressionTestRunner(_testimpl, "id",
@@ -260,7 +262,7 @@
_expression));
}
- public void testSetValueExpression() throws Exception
+ public void testValueExpression() throws Exception
{
expect(_expression.isLiteralText()).andReturn(false);
_mocksControl.replay();
@@ -269,17 +271,17 @@
assertEquals(_expression, _testimpl.getValueExpression("xxx"));
_testimpl.setValueExpression("xxx", null);
_mocksControl.verify();
+
assertNull(_testimpl.getValueExpression("xxx"));
assertNull(_testimpl.bindings);
}
- public void testSetValueExpressionWithExceptionOnGetValue() throws Exception
+ public void testValueExpressionWithExceptionOnGetValue() throws Exception
{
- assertSetValueExpressionWithExceptionOnGetValue(FacesException.class, new ELException());
+ assertValueExpressionWithExceptionOnGetValue(FacesException.class, new ELException());
}
- private void assertSetValueExpressionWithExceptionOnGetValue(Class<? extends Throwable> expected,
- Throwable fired)
+ private void assertValueExpressionWithExceptionOnGetValue(Class<? extends Throwable> expected, Throwable fired)
{
expect(_expression.isLiteralText()).andReturn(true);
expect(_testimpl.getFacesContext()).andReturn(_facesContext);
@@ -298,7 +300,7 @@
_mocksControl.reset();
}
- public void testSetValueExpressionWithLiteralText() throws Exception
+ public void testValueExpressionWithLiteralText() throws Exception
{
expect(_expression.isLiteralText()).andReturn(true);
expect(_testimpl.getFacesContext()).andReturn(_facesContext);
@@ -311,6 +313,22 @@
assertEquals("abc", map.get("xxx"));
_mocksControl.verify();
assertNull(_testimpl.getValueExpression("xxx"));
+ }
+
+ public void testValueExpressionWithValueBindingFallback() throws Exception
+ {
+ ValueBinding valueBinding = _mocksControl.createMock(ValueBinding.class);
+ expect(_testimpl.getValueBinding("xxx")).andReturn(valueBinding);
+ _mocksControl.replay();
+ ValueExpression valueExpression = _testimpl.getValueExpression("xxx");
+ _mocksControl.verify();
+ assertTrue(valueExpression instanceof _ValueBindingToValueExpression);
+ _mocksControl.reset();
+ expect(_elContext.getContext(eq(FacesContext.class))).andReturn(_facesContext);
+ expect(valueBinding.getValue(eq(_facesContext))).andReturn("value");
+ _mocksControl.replay();
+ assertEquals("value", valueExpression.getValue(_elContext));
+ _mocksControl.verify();
}
}