Author: nbelaevski
Date: 2009-12-15 14:13:37 -0500 (Tue, 15 Dec 2009)
New Revision: 16142
Added:
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/MethodBindingMethodExpressionAdaptorTest.java
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/ValueBindingValueExpressionAdaptorTest.java
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/MethodBindingMethodExpressionAdaptor.java
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java
branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
Log:
https://jira.jboss.org/jira/browse/RFPL-295
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/MethodBindingMethodExpressionAdaptor.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/MethodBindingMethodExpressionAdaptor.java 2009-12-15
18:21:49 UTC (rev 16141)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/MethodBindingMethodExpressionAdaptor.java 2009-12-15
19:13:37 UTC (rev 16142)
@@ -20,9 +20,12 @@
*/
package org.richfaces.webapp.taglib;
+import java.io.Serializable;
+
import javax.el.ELException;
import javax.el.MethodExpression;
import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
@@ -34,10 +37,17 @@
*
*/
@SuppressWarnings("deprecation")
-public class MethodBindingMethodExpressionAdaptor extends MethodBinding implements
StateHolder{
+public class MethodBindingMethodExpressionAdaptor extends MethodBinding implements
StateHolder, Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 225772153283234069L;
+
private MethodExpression expression;
+
private boolean tranzient;
+
/* (non-Javadoc)
* @see javax.faces.el.MethodBinding#getType(javax.faces.context.FacesContext)
*/
@@ -79,11 +89,24 @@
}
public void restoreState(FacesContext context, Object state) {
- expression = (MethodExpression) state;
+ if (state instanceof MethodExpression) {
+ expression = (MethodExpression) state;
+ } else {
+ expression = (MethodExpression) UIComponentBase.saveAttachedState(context, state);
+ }
}
public Object saveState(FacesContext context) {
- return expression;
+ Object result = null;
+ if (!tranzient) {
+ if (expression instanceof StateHolder) {
+ result = UIComponentBase.saveAttachedState(context, expression);
+ } else {
+ result = expression;
+ }
+ }
+
+ return result;
}
public void setTransient(boolean newTransientValue) {
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java 2009-12-15
18:21:49 UTC (rev 16141)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java 2009-12-15
19:13:37 UTC (rev 16142)
@@ -113,15 +113,24 @@
}
public void restoreState(FacesContext context, Object state) {
- expression = (ValueExpression) UIComponentBase.restoreAttachedState(context, state);
+ if (state instanceof ValueExpression) {
+ expression = (ValueExpression) state;
+ } else {
+ expression = (ValueExpression) UIComponentBase.restoreAttachedState(context, state);
+ }
}
public Object saveState(FacesContext context) {
+ Object result = null;
if (!tranzient) {
- return UIComponentBase.saveAttachedState(context, expression);
- } else {
- return null;
+ if (expression instanceof StateHolder) {
+ result = UIComponentBase.saveAttachedState(context, expression);
+ } else {
+ result = expression;
+ }
}
+
+ return result;
}
public void setTransient(boolean newTransientValue) {
Modified:
branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
===================================================================
---
branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2009-12-15
18:21:49 UTC (rev 16141)
+++
branches/community/3.3.X/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2009-12-15
19:13:37 UTC (rev 16142)
@@ -89,8 +89,7 @@
*/
@Override
public void setValue(ELContext context, Object value) {
- value = value;
-
+ this.value = value;
}
/* (non-Javadoc)
Added:
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/MethodBindingMethodExpressionAdaptorTest.java
===================================================================
---
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/MethodBindingMethodExpressionAdaptorTest.java
(rev 0)
+++
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/MethodBindingMethodExpressionAdaptorTest.java 2009-12-15
19:13:37 UTC (rev 16142)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.ajax4jsf.webapp.taglib;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+
+import com.sun.faces.application.MethodBindingMethodExpressionAdapter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MethodBindingMethodExpressionAdaptorTest extends
+ AbstractAjax4JsfTestCase {
+
+ public MethodBindingMethodExpressionAdaptorTest(String name) {
+ super(name);
+ }
+
+ public static class TestMethodExpression extends MethodExpression {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8789388146351873628L;
+
+ private String returnValue;
+
+ public TestMethodExpression() {
+ this(null);
+ }
+
+ public TestMethodExpression(String returnValue) {
+ super();
+ this.returnValue = returnValue;
+ }
+
+ public String getReturnValue() {
+ return returnValue;
+ }
+
+ public void setReturnValue(String returnValue) {
+ this.returnValue = returnValue;
+ }
+
+ @Override
+ public MethodInfo getMethodInfo(ELContext context) {
+ return null;
+ }
+
+ @Override
+ public Object invoke(ELContext context, Object[] params) {
+ return returnValue;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return false;
+ }
+
+ @Override
+ public String getExpressionString() {
+ return null;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+ @Override
+ public boolean isLiteralText() {
+ return false;
+ }
+
+ }
+
+ public static final class StateHolderTestMethodExpression extends TestMethodExpression
+ implements StateHolder {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4430232388824229636L;
+
+ public StateHolderTestMethodExpression() {
+ super();
+ }
+
+ public StateHolderTestMethodExpression(String string) {
+ super(string);
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ setReturnValue((String) state);
+ }
+
+ public Object saveState(FacesContext context) {
+ return getReturnValue();
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ }
+
+ }
+
+ private MethodBindingMethodExpressionAdapter saveRestoreState(
+ MethodBindingMethodExpressionAdapter adaptor) {
+ MethodBindingMethodExpressionAdapter restoredAdaptor = new
MethodBindingMethodExpressionAdapter();
+ restoredAdaptor.restoreState(facesContext, adaptor
+ .saveState(facesContext));
+ return restoredAdaptor;
+ }
+
+ private MethodBindingMethodExpressionAdapter serializeDeserialize(
+ MethodBindingMethodExpressionAdapter adaptor) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ try {
+ oos.writeObject(adaptor);
+ } finally {
+ oos.close();
+ }
+
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+ baos.toByteArray()));
+ try {
+ return (MethodBindingMethodExpressionAdapter) ois.readObject();
+ } finally {
+ ois.close();
+ }
+ }
+
+ public void testSaveRestoreState() throws Exception {
+ MethodBindingMethodExpressionAdapter adaptor1 = new
MethodBindingMethodExpressionAdapter(
+ new TestMethodExpression("testValue1"));
+
+ assertEquals("testValue1", saveRestoreState(adaptor1).invoke(facesContext,
null));
+
+ MethodBindingMethodExpressionAdapter adaptor2 = new
MethodBindingMethodExpressionAdapter(
+ new StateHolderTestMethodExpression("testValue2"));
+
+ assertEquals("testValue2", saveRestoreState(adaptor2).invoke(facesContext,
null));
+ }
+
+ public void testSerializeDeserialize() throws Exception {
+ MethodBindingMethodExpressionAdapter adaptor1 = new
MethodBindingMethodExpressionAdapter(
+ new TestMethodExpression("testValue1"));
+
+ assertEquals("testValue1",
serializeDeserialize(adaptor1).invoke(facesContext, null));
+
+ MethodBindingMethodExpressionAdapter adaptor2 = new
MethodBindingMethodExpressionAdapter(
+ new StateHolderTestMethodExpression("testValue2"));
+
+ assertEquals("testValue2",
serializeDeserialize(adaptor2).invoke(facesContext, null));
+ }
+}
Added:
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/ValueBindingValueExpressionAdaptorTest.java
===================================================================
---
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/ValueBindingValueExpressionAdaptorTest.java
(rev 0)
+++
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/webapp/taglib/ValueBindingValueExpressionAdaptorTest.java 2009-12-15
19:13:37 UTC (rev 16142)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.ajax4jsf.webapp.taglib;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockValueExpression;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.richfaces.webapp.taglib.ValueBindingValueExpressionAdaptor;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ValueBindingValueExpressionAdaptorTest extends
+ AbstractAjax4JsfTestCase {
+
+ public ValueBindingValueExpressionAdaptorTest(String name) {
+ super(name);
+ }
+
+ public static final class StateHolderTestValueExpression extends
+ MockValueExpression implements StateHolder {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4288036600538778835L;
+
+ public StateHolderTestValueExpression() {
+ super(null);
+ }
+
+ public StateHolderTestValueExpression(Object value) {
+ super(value);
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ setValue(context.getELContext(), state);
+ }
+
+ public Object saveState(FacesContext context) {
+ return getValue(context.getELContext());
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ }
+
+ }
+
+ private ValueBindingValueExpressionAdaptor saveRestoreState(
+ ValueBindingValueExpressionAdaptor adaptor) {
+ ValueBindingValueExpressionAdaptor restoredAdaptor = new
ValueBindingValueExpressionAdaptor();
+ restoredAdaptor.restoreState(facesContext, adaptor
+ .saveState(facesContext));
+ return restoredAdaptor;
+ }
+
+ private ValueBindingValueExpressionAdaptor serializeDeserialize(
+ ValueBindingValueExpressionAdaptor adaptor) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ try {
+ oos.writeObject(adaptor);
+ } finally {
+ oos.close();
+ }
+
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
+ baos.toByteArray()));
+ try {
+ return (ValueBindingValueExpressionAdaptor) ois.readObject();
+ } finally {
+ ois.close();
+ }
+ }
+
+ public void testSaveRestoreState() throws Exception {
+ ValueBindingValueExpressionAdaptor adaptor1 = new ValueBindingValueExpressionAdaptor(
+ new MockValueExpression("testValue1"));
+
+ assertEquals("testValue1", saveRestoreState(adaptor1).getValue(
+ facesContext));
+
+ ValueBindingValueExpressionAdaptor adaptor2 = new ValueBindingValueExpressionAdaptor(
+ new StateHolderTestValueExpression("testValue2"));
+
+ assertEquals("testValue2", saveRestoreState(adaptor2).getValue(
+ facesContext));
+ }
+
+ public void testSerializeDeserialize() throws Exception {
+ ValueBindingValueExpressionAdaptor adaptor1 = new ValueBindingValueExpressionAdaptor(
+ new MockValueExpression("testValue1"));
+
+ assertEquals("testValue1", serializeDeserialize(adaptor1).getValue(
+ facesContext));
+
+ ValueBindingValueExpressionAdaptor adaptor2 = new ValueBindingValueExpressionAdaptor(
+ new StateHolderTestValueExpression("testValue2"));
+
+ assertEquals("testValue2", serializeDeserialize(adaptor2).getValue(
+ facesContext));
+ }
+}