You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/08/13 15:29:26 UTC
svn commit: r985190 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/util/
tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/ ...
Author: lofwyr
Date: Fri Aug 13 13:29:25 2010
New Revision: 985190
URL: http://svn.apache.org/viewvc?rev=985190&view=rev
Log:
clean up: add util-method for invoke method expression with an event
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITabGroup.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/FacesUtils.java
myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionStateChangeListener.java
myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTabChangeListener.java
myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTreeExpansionListener.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java Fri Aug 13 13:29:25 2010
@@ -39,7 +39,6 @@ import org.apache.myfaces.tobago.layout.
import org.apache.myfaces.tobago.layout.LayoutTokens;
import org.apache.myfaces.tobago.model.SheetState;
import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer;
-import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -331,18 +330,18 @@ public abstract class AbstractUISheet ex
public void broadcast(FacesEvent facesEvent) throws AbortProcessingException {
super.broadcast(facesEvent);
if (facesEvent instanceof SheetStateChangeEvent) {
- ComponentUtils.invokeMethodBinding(getFacesContext(), getStateChangeListener(), facesEvent);
+ FacesUtils.invokeMethodBinding(getFacesContext(), getStateChangeListener(), facesEvent);
} else if (facesEvent instanceof PageActionEvent) {
if (facesEvent.getComponent() == this) {
performPaging((PageActionEvent) facesEvent);
- ComponentUtils.invokeMethodBinding(
+ FacesUtils.invokeMethodBinding(
getFacesContext(), getStateChangeListener(), new SheetStateChangeEvent(this));
}
} else if (facesEvent instanceof SortActionEvent) {
getSheetState(getFacesContext()).updateSortState((SortActionEvent) facesEvent);
MethodBinding methodBinding = getSortActionListener();
if (methodBinding!= null) {
- ComponentUtils.invokeMethodBinding(getFacesContext(), methodBinding, facesEvent);
+ FacesUtils.invokeMethodBinding(getFacesContext(), methodBinding, facesEvent);
} else {
new Sorter().perform((SortActionEvent) facesEvent);
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITabGroup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITabGroup.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITabGroup.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITabGroup.java Fri Aug 13 13:29:25 2010
@@ -31,7 +31,6 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.layout.LayoutComponent;
import org.apache.myfaces.tobago.layout.LayoutContainer;
import org.apache.myfaces.tobago.layout.LayoutManager;
-import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -202,9 +201,9 @@ public abstract class AbstractUITabGroup
setSelectedIndex(index);
}
- ComponentUtils.invokeMethodBinding(getFacesContext(), getTabChangeListener(), facesEvent);
+ FacesUtils.invokeMethodBinding(getFacesContext(), getTabChangeListener(), facesEvent);
- ComponentUtils.invokeMethodBinding(getFacesContext(), getActionListener(), facesEvent);
+ FacesUtils.invokeMethodBinding(getFacesContext(), getActionListener(), facesEvent);
ActionListener defaultActionListener = getFacesContext().getApplication().getActionListener();
if (defaultActionListener != null) {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java Fri Aug 13 13:29:25 2010
@@ -17,6 +17,7 @@ package org.apache.myfaces.tobago.intern
* limitations under the License.
*/
+import org.apache.myfaces.tobago.compat.FacesUtils;
import org.apache.myfaces.tobago.component.SupportsMarkup;
import org.apache.myfaces.tobago.component.TreeModelBuilder;
import org.apache.myfaces.tobago.config.Configurable;
@@ -24,7 +25,6 @@ import org.apache.myfaces.tobago.event.T
import org.apache.myfaces.tobago.event.TreeExpansionListener;
import org.apache.myfaces.tobago.model.MixedTreeModel;
import org.apache.myfaces.tobago.model.TreePath;
-import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -210,7 +210,7 @@ public abstract class AbstractUITreeNode
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
if (event instanceof TreeExpansionEvent) {
- ComponentUtils.invokeMethodBinding(getFacesContext(), getTreeExpansionListener(), event);
+ FacesUtils.invokeMethodBinding(getFacesContext(), getTreeExpansionListener(), event);
}
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Fri Aug 13 13:29:25 2010
@@ -51,13 +51,10 @@ import javax.faces.component.UISelectMan
import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
-import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
-import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
-import javax.faces.event.FacesEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.render.RenderKit;
@@ -875,18 +872,4 @@ public class ComponentUtils {
return null;
}
- public static void invokeMethodBinding(FacesContext facesContext, MethodBinding methodBinding, FacesEvent event) {
- if (methodBinding != null && event != null) {
- try {
- methodBinding.invoke(facesContext, new Object[]{event});
- } catch (EvaluationException e) {
- Throwable cause = e.getCause();
- if (cause instanceof AbortProcessingException) {
- throw (AbortProcessingException) cause;
- } else {
- throw e;
- }
- }
- }
- }
}
Modified: myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/FacesUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/FacesUtils.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/FacesUtils.java (original)
+++ myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/compat/FacesUtils.java Fri Aug 13 13:29:25 2010
@@ -17,12 +17,12 @@ package org.apache.myfaces.tobago.compat
* limitations under the License.
*/
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.myfaces.tobago.event.TabChangeSource;
import org.apache.myfaces.tobago.event.ValueExpressionPopupActionListener;
import org.apache.myfaces.tobago.event.ValueExpressionTabChangeListener;
import org.apache.myfaces.tobago.util.ValueExpressionComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
@@ -30,10 +30,13 @@ import javax.faces.component.ActionSourc
import javax.faces.component.ContextCallback;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
-import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
import javax.faces.validator.MethodExpressionValidator;
import java.util.Comparator;
@@ -41,8 +44,8 @@ public class FacesUtils {
private static final Logger LOG = LoggerFactory.getLogger(FacesUtils.class);
- public static boolean invokeOnComponent(FacesContext context, UIComponent component,
- String clientId, ContextCallback callback) {
+ public static boolean invokeOnComponent(
+ FacesContext context, UIComponent component, String clientId, ContextCallback callback) {
String thisClientId = component.getClientId(context);
if (clientId.equals(thisClientId)) {
@@ -68,8 +71,8 @@ public class FacesUtils {
return false;
}
- private static boolean invokeOnComponentFacetsAndChildren(FacesContext context, UIComponent component,
- String clientId, ContextCallback callback) {
+ private static boolean invokeOnComponentFacetsAndChildren(
+ FacesContext context, UIComponent component, String clientId, ContextCallback callback) {
for (java.util.Iterator<UIComponent> it = component.getFacetsAndChildren(); it.hasNext();) {
UIComponent child = it.next();
@@ -80,9 +83,35 @@ public class FacesUtils {
return false;
}
+ public static void invokeMethodBinding(FacesContext facesContext, MethodBinding methodBinding, FacesEvent event) {
+ if (methodBinding != null && event != null) {
+ try {
+ methodBinding.invoke(facesContext, new Object[]{event});
+ } catch (EvaluationException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof AbortProcessingException) {
+ throw (AbortProcessingException) cause;
+ } else {
+ throw e;
+ }
+ }
+ }
+ }
+
+ public static void invokeMethodBinding(
+ FacesContext facesContext, MethodExpression methodExpression, FacesEvent event) {
+
+ if (methodExpression != null && event != null) {
+ try {
+ methodExpression.invoke(facesContext.getELContext(), new Object[]{event});
+ } catch (Exception e) {
+ throw new AbortProcessingException(e);
+ }
+ }
+ }
- public static Object getValueFromValueBindingOrValueExpression(FacesContext context, UIComponent component,
- String name) {
+ public static Object getValueFromValueBindingOrValueExpression(
+ FacesContext context, UIComponent component, String name) {
return component.getValueExpression(name).getValue(context.getELContext());
}
@@ -91,8 +120,8 @@ public class FacesUtils {
return component.getValueExpression(name) != null;
}
- public static boolean isReadonlyValueBindingOrValueExpression(FacesContext context,
- UIComponent component, String name) {
+ public static boolean isReadonlyValueBindingOrValueExpression(
+ FacesContext context, UIComponent component, String name) {
return component.getValueExpression(name).isReadOnly(context.getELContext());
}
@@ -101,24 +130,24 @@ public class FacesUtils {
return component.getValueExpression(name).getExpressionString();
}
- public static void setValueOfBindingOrExpression(FacesContext context, Object value,
- UIComponent component, String bindingName) {
+ public static void setValueOfBindingOrExpression(
+ FacesContext context, Object value, UIComponent component, String bindingName) {
ValueExpression ve = component.getValueExpression(bindingName);
if (ve != null) {
ve.setValue(context.getELContext(), value);
}
}
- public static void setValueOfBindingOrExpression(FacesContext context, Object value,
- Object bindingOrExpression) {
+ public static void setValueOfBindingOrExpression(
+ FacesContext context, Object value, Object bindingOrExpression) {
if (bindingOrExpression instanceof ValueExpression) {
ValueExpression ve = (ValueExpression) bindingOrExpression;
ve.setValue(context.getELContext(), value);
}
}
- public static void copyValueBindingOrValueExpression(UIComponent fromComponent, String fromName,
- UIComponent toComponent, String toName) {
+ public static void copyValueBindingOrValueExpression(
+ UIComponent fromComponent, String fromName, UIComponent toComponent, String toName) {
ValueExpression ve = fromComponent.getValueExpression(fromName);
if (ve != null) {
toComponent.setValueExpression(toName, ve);
@@ -157,15 +186,15 @@ public class FacesUtils {
component.setValueExpression(name, (ValueExpression) valueBindingOrExpression);
}
- public static void addBindingOrExpressionTabChangeListener(TabChangeSource source, String type,
- Object bindingOrExpression) {
+ public static void addBindingOrExpressionTabChangeListener(
+ TabChangeSource source, String type, Object bindingOrExpression) {
if (bindingOrExpression instanceof ValueExpression) {
source.addTabChangeListener(new ValueExpressionTabChangeListener(type, (ValueExpression) bindingOrExpression));
}
}
- public static Comparator getBindingOrExpressionComparator(FacesContext facesContext, UIComponent child, String var,
- boolean descending, Comparator comparator) {
+ public static Comparator getBindingOrExpressionComparator(
+ FacesContext facesContext, UIComponent child, String var, boolean descending, Comparator comparator) {
ValueExpression valueBinding = child.getValueExpression("value");
return new ValueExpressionComparator(facesContext, var, valueBinding, descending, comparator);
}
Modified: myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionStateChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionStateChangeListener.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionStateChangeListener.java (original)
+++ myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionStateChangeListener.java Fri Aug 13 13:29:25 2010
@@ -17,13 +17,13 @@ package org.apache.myfaces.tobago.event;
* limitations under the License.
*/
-import javax.el.ELContext;
+import org.apache.myfaces.tobago.compat.FacesUtils;
+
import javax.el.MethodExpression;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-
public class MethodExpressionStateChangeListener implements SheetStateChangeListener, StateHolder {
private MethodExpression methodExpression;
@@ -38,16 +38,7 @@ public class MethodExpressionStateChange
}
public void processSheetStateChange(SheetStateChangeEvent actionEvent) throws AbortProcessingException {
- try {
- Object[] params = new Object[]{actionEvent};
- methodExpression.invoke(elContext(), params);
- } catch (Exception e) {
- throw new AbortProcessingException(e);
- }
- }
-
- private ELContext elContext() {
- return FacesContext.getCurrentInstance().getELContext();
+ FacesUtils.invokeMethodBinding(FacesContext.getCurrentInstance(), methodExpression, actionEvent);
}
public void restoreState(FacesContext context, Object state) {
Modified: myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTabChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTabChangeListener.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTabChangeListener.java (original)
+++ myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTabChangeListener.java Fri Aug 13 13:29:25 2010
@@ -17,7 +17,8 @@ package org.apache.myfaces.tobago.event;
* limitations under the License.
*/
-import javax.el.ELContext;
+import org.apache.myfaces.tobago.compat.FacesUtils;
+
import javax.el.MethodExpression;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
@@ -37,16 +38,7 @@ public class MethodExpressionTabChangeLi
}
public void processTabChange(TabChangeEvent actionEvent) throws AbortProcessingException {
- try {
- Object[] params = new Object[]{actionEvent};
- methodExpression.invoke(elContext(), params);
- } catch (Exception e) {
- throw new AbortProcessingException(e);
- }
- }
-
- private ELContext elContext() {
- return FacesContext.getCurrentInstance().getELContext();
+ FacesUtils.invokeMethodBinding(FacesContext.getCurrentInstance(), methodExpression, actionEvent);
}
public void restoreState(FacesContext context, Object state) {
Modified: myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTreeExpansionListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTreeExpansionListener.java?rev=985190&r1=985189&r2=985190&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTreeExpansionListener.java (original)
+++ myfaces/tobago/trunk/tobago-jsf-compat/src/main/java-jsf-1.2/org/apache/myfaces/tobago/event/MethodExpressionTreeExpansionListener.java Fri Aug 13 13:29:25 2010
@@ -17,11 +17,12 @@ package org.apache.myfaces.tobago.event;
* limitations under the License.
*/
+import org.apache.myfaces.tobago.compat.FacesUtils;
+
import javax.el.ELContext;
import javax.el.MethodExpression;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
public class MethodExpressionTreeExpansionListener implements TreeExpansionListener, StateHolder {
@@ -38,12 +39,7 @@ public class MethodExpressionTreeExpansi
}
public void treeExpanded(TreeExpansionEvent event) {
- try {
- Object[] params = new Object[]{event};
- methodExpression.invoke(elContext(), params);
- } catch (Exception e) {
- throw new AbortProcessingException(e);
- }
+ FacesUtils.invokeMethodBinding(FacesContext.getCurrentInstance(), methodExpression, event);
}
private ELContext elContext() {
@@ -65,5 +61,4 @@ public class MethodExpressionTreeExpansi
public boolean isTransient() {
return isTransient;
}
-
}