Author: Alex.Kolonitsky
Date: 2010-09-03 04:56:24 -0400 (Fri, 03 Sep 2010)
New Revision: 19108
Added:
trunk/ui/common/ui/src/main/java/org/richfaces/event/
trunk/ui/common/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java
Removed:
trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java
trunk/ui/output/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ChangeExpandListenerHandler.java
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
Log:
Share general implimentation of ListenerHandler and MethodExpressionEventListener
Copied:
trunk/ui/common/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java
(from rev 19094,
trunk/ui/output/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java)
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java
(rev 0)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -0,0 +1,197 @@
+/*
+ * 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.richfaces.event;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.MethodNotFoundException;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * <p><strong><span
+ *
class="changed_modified_2_0">MethodExpressionEventListener</span></strong>
+ * is a {@link FacesListener} that wraps a {@link
+ * MethodExpression}. When it receives a {@link FacesEvent}, it
+ * executes a method on an object identified by the {@link
+ * MethodExpression}.</p>
+ *
+ * @author akolonitsky
+ * @version 1.0
+ *
+ */
+public abstract class MethodExpressionEventListener implements FacesListener, StateHolder
{
+
+ private static final Class<?>[] EVENT_LISTENER_ZERO_ARG_SIG = new Class[] { };
+
+ private static final Object[] NO_PARAMS = new Object[0];
+
+ // ------------------------------------------------------ Instance Variables
+
+ private MethodExpression methodExpressionOneArg = null;
+ private MethodExpression methodExpressionZeroArg = null;
+
+ private boolean isTransient;
+
+ protected MethodExpressionEventListener() {
+ }
+
+ /**
+ * <p><span class="changed_modified_2_0">Construct</span>
a {@link
+ * FacesListener} that contains a {@link
+ * MethodExpression}.<span
+ * class="changed_added_2_0">To accomodate method expression targets
+ * that take no arguments instead of taking a {@link
+ * FacesEvent} argument</span>, the implementation of this
+ * class must take the argument <code>methodExpressionOneArg</code>,
+ * extract its expression string, and create another
+ * <code>MethodExpression</code> whose expected param types match
+ * those of a zero argument method. The usage requirements for both
+ * of these <code>MethodExpression</code> instances are described in
+ * {@link #processEvent}.</span></p>
+ *
+ * @param methodExpressionOneArg a <code>MethodExpression</code>
+ * that points to a method that returns <code>void</code> and takes
+ * a single argument of type {@link FacesEvent}.
+ */
+ protected MethodExpressionEventListener(MethodExpression methodExpressionOneArg) {
+
+ super();
+ this.methodExpressionOneArg = methodExpressionOneArg;
+ FacesContext context = FacesContext.getCurrentInstance();
+ ELContext elContext = context.getELContext();
+ this.methodExpressionZeroArg =
context.getApplication().getExpressionFactory().createMethodExpression(
+ elContext, methodExpressionOneArg.getExpressionString(), Void.class,
EVENT_LISTENER_ZERO_ARG_SIG);
+ }
+
+ /**
+ * <p>Construct a {@link FacesListener} that contains a {@link
MethodExpression}.</p>
+ *
+ * @param methodExprOneArg
+ * @param methodExprZeroArg
+ */
+ protected MethodExpressionEventListener(MethodExpression methodExprOneArg,
MethodExpression methodExprZeroArg) {
+
+ super();
+ this.methodExpressionOneArg = methodExprOneArg;
+ this.methodExpressionZeroArg = methodExprZeroArg;
+ }
+
+ // ------------------------------------------------------- Event Method
+
+ /**
+ * <p><span class="changed_modified_2_0">Call</span>
through to the
+ * {@link MethodExpression} passed in our constructor. <span
+ * class="changed_added_2_0">First, try to invoke the
+ * <code>MethodExpression</code> passed to the constructor of this
+ * instance, passing the argument {@link FacesEvent} as the
+ * argument. If a {@link MethodNotFoundException} is thrown, call
+ * to the zero argument <code>MethodExpression</code> derived from
+ * the <code>MethodExpression</code> passed to the constructor of
+ * this instance. If that fails for any reason, throw an {@link
+ * AbortProcessingException}, including the cause of the
+ * failure.</span></p>
+ *
+ * @throws NullPointerException {@inheritDoc}
+ * @throws AbortProcessingException {@inheritDoc}
+ */
+ public void processEvent(FacesEvent event) throws AbortProcessingException {
+
+ if (event == null) {
+ throw new NullPointerException();
+ }
+ FacesContext context = FacesContext.getCurrentInstance();
+ ELContext elContext = context.getELContext();
+ // PENDING: The corresponding code in MethodExpressionActionListener
+ // has an elaborate message capture, logging, and rethrowing block.
+ // Why not here?
+ try {
+ methodExpressionOneArg.invoke(elContext, new Object[] {event});
+ } catch (MethodNotFoundException mnf) {
+ if (null != methodExpressionZeroArg) {
+
+ try {
+ // try to invoke a no-arg version
+ methodExpressionZeroArg.invoke(elContext, NO_PARAMS);
+ } catch (ELException e) {
+ throw new AbortProcessingException(e.getMessage(), e.getCause());
+ }
+ }
+ } catch (ELException e) {
+ throw new AbortProcessingException(e.getMessage(), e.getCause());
+ }
+ }
+
+
+ // ------------------------------------------------ Methods from StateHolder
+
+
+ /**
+ * <p class="changed_modified_2_0">Both {@link MethodExpression}
+ * instances described in the constructor must be saved.</p>
+ */
+ public Object saveState(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ return new Object[] {
+ UIComponentBase.saveAttachedState(context, methodExpressionOneArg),
+ UIComponentBase.saveAttachedState(context, methodExpressionZeroArg)
+ };
+ }
+
+
+ /**
+ * <p class="changed_modified_2_0">Both {@link MethodExpression}
+ * instances described in the constructor must be restored.</p>
+ */
+ public void restoreState(FacesContext context, Object state) {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (state == null) {
+ return;
+ }
+
+ methodExpressionOneArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[0]);
+ methodExpressionZeroArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[1]);
+ }
+
+
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ isTransient = newTransientValue;
+ }
+}
Copied:
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java
(from rev 19094,
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java)
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java
(rev 0)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -0,0 +1,145 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.view.facelets.html;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.view.EditableValueHolderAttachedObjectHandler;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributeException;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.TagHandler;
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * @author akolonitsky
+ * @since Aug 31, 2010
+ */
+public abstract class EventListenerHandler extends TagHandler implements
EditableValueHolderAttachedObjectHandler {
+
+ protected final TagAttribute binding;
+
+ protected final String listenerType;
+
+ public abstract static class LazyEventListener<L extends FacesListener>
implements FacesListener, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final String type;
+
+ protected final ValueExpression binding;
+
+ protected LazyEventListener(String type, ValueExpression binding) {
+ this.type = type;
+ this.binding = binding;
+ }
+
+ public void processEvent(FacesEvent event) throws AbortProcessingException {
+
+ FacesContext faces = FacesContext.getCurrentInstance();
+ if (faces == null) {
+ return;
+ }
+
+ L instance = null;
+ if (this.binding != null) {
+ instance = (L) binding.getValue(faces.getELContext());
+ }
+ if (instance == null && this.type != null) {
+ try {
+ instance = (L) forName(this.type).newInstance();
+ } catch (Exception e) {
+ throw new AbortProcessingException("Couldn't Lazily
instantiate EventListener", e);
+ }
+ if (this.binding != null) {
+ binding.setValue(faces.getELContext(), instance);
+ }
+ }
+
+ if (instance != null) {
+ event.processListener(instance);
+ }
+ }
+ }
+
+ public EventListenerHandler(TagConfig config) {
+ super(config);
+ this.binding = this.getAttribute("binding");
+ TagAttribute type = this.getAttribute("type");
+ if (type != null) {
+ if (type.isLiteral()) {
+ try {
+ forName(type.getValue());
+ } catch (ClassNotFoundException e) {
+ throw new TagAttributeException(type, "Couldn't qualify
EventListener", e);
+ }
+ } else {
+ throw new TagAttributeException(type, "Must be a literal class name
of type EventListener");
+ }
+ this.listenerType = type.getValue();
+ } else {
+ this.listenerType = null;
+ }
+ }
+
+ public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
+
+ // only process if it's been created
+ if (parent == null || !ComponentHandler.isNew(parent)) {
+ return;
+ }
+
+ if (isEventSource(parent)) {
+ applyAttachedObject(ctx.getFacesContext(), parent);
+ } else if (UIComponent.isCompositeComponent(parent)) {
+ // Allow the composite component to know about the target component.
+ TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
+ } else {
+ throw new TagException(this.tag, "Parent is not of type
EditableValueHolder, type is: " + parent);
+ }
+ }
+
+ public String getFor() {
+ TagAttribute attr = this.getAttribute("for");
+ return attr == null ? null : attr.getValue();
+ }
+
+ public static Class<?> forName(String name) throws ClassNotFoundException {
+ if (null == name || "".equals(name)) {
+ return null;
+ }
+
+ return Class.forName(name, false,
Thread.currentThread().getContextClassLoader());
+ }
+
+ public abstract boolean isEventSource(UIComponent comp);
+}
+
+
Copied:
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java
(from rev 19094,
trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java)
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java
(rev 0)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richfaces.view.facelets.html;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.view.AttachedObjectHandler;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class TagHandlerUtils {
+
+ // TODO - is that implementation dependency?
+ private static final String JAVAX_FACES_RETARGETABLE_HANDLERS =
"javax.faces.RetargetableHandlers";
+
+ private TagHandlerUtils() {
+ //utility class constructor
+ }
+
+ static List<AttachedObjectHandler>
getOrCreateRetargetableHandlersList(UIComponent component) {
+ Map<String, Object> attrs = component.getAttributes();
+ @SuppressWarnings({
+ "unchecked"}) List<AttachedObjectHandler> list =
+ (List<AttachedObjectHandler>)
attrs.get(JAVAX_FACES_RETARGETABLE_HANDLERS);
+
+ if (list == null) {
+ list = new ArrayList<AttachedObjectHandler>();
+ attrs.put(JAVAX_FACES_RETARGETABLE_HANDLERS, list);
+ }
+
+ return list;
+ }
+
+ static <T> Class<? extends T> loadClass(String className, Class<T>
type)
+ throws ClassNotFoundException, ClassCastException {
+
+ ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+ Class<?> loadedClass = Class.forName(className, false, ccl);
+
+ return loadedClass.asSubclass(type);
+ }
+
+}
Deleted:
trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java 2010-09-03
08:39:33 UTC (rev 19107)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/view/facelets/html/TagHandlerUtils.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.richfaces.view.facelets.html;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.view.AttachedObjectHandler;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class TagHandlerUtils {
-
- // TODO - is that implementation dependency?
- private static final String JAVAX_FACES_RETARGETABLE_HANDLERS =
"javax.faces.RetargetableHandlers";
-
- private TagHandlerUtils() {
- //utility class constructor
- }
-
- static List<AttachedObjectHandler>
getOrCreateRetargetableHandlersList(UIComponent component) {
- Map<String, Object> attrs = component.getAttributes();
- @SuppressWarnings({
- "unchecked"}) List<AttachedObjectHandler> list =
- (List<AttachedObjectHandler>)
attrs.get(JAVAX_FACES_RETARGETABLE_HANDLERS);
-
- if (list == null) {
- list = new ArrayList<AttachedObjectHandler>();
- attrs.put(JAVAX_FACES_RETARGETABLE_HANDLERS, list);
- }
-
- return list;
- }
-
- static <T> Class<? extends T> loadClass(String className, Class<T>
type)
- throws ClassNotFoundException, ClassCastException {
-
- ClassLoader ccl = Thread.currentThread().getContextClassLoader();
- Class<?> loadedClass = Class.forName(className, false, ccl);
-
- return loadedClass.asSubclass(type);
- }
-
-}
Deleted:
trunk/ui/output/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java 2010-09-03
08:39:33 UTC (rev 19107)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/event/MethodExpressionEventListener.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -1,197 +0,0 @@
-/*
- * 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.richfaces.event;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.MethodExpression;
-import javax.el.MethodNotFoundException;
-import javax.faces.component.StateHolder;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-
-/**
- * <p><strong><span
- *
class="changed_modified_2_0">MethodExpressionEventListener</span></strong>
- * is a {@link FacesListener} that wraps a {@link
- * MethodExpression}. When it receives a {@link FacesEvent}, it
- * executes a method on an object identified by the {@link
- * MethodExpression}.</p>
- *
- * @author akolonitsky
- * @version 1.0
- *
- */
-public abstract class MethodExpressionEventListener implements FacesListener, StateHolder
{
-
- private static final Class<?>[] EVENT_LISTENER_ZERO_ARG_SIG = new Class[] { };
-
- private static final Object[] NO_PARAMS = new Object[0];
-
- // ------------------------------------------------------ Instance Variables
-
- private MethodExpression methodExpressionOneArg = null;
- private MethodExpression methodExpressionZeroArg = null;
-
- private boolean isTransient;
-
- protected MethodExpressionEventListener() {
- }
-
- /**
- * <p><span class="changed_modified_2_0">Construct</span>
a {@link
- * FacesListener} that contains a {@link
- * MethodExpression}.<span
- * class="changed_added_2_0">To accomodate method expression targets
- * that take no arguments instead of taking a {@link
- * FacesEvent} argument</span>, the implementation of this
- * class must take the argument <code>methodExpressionOneArg</code>,
- * extract its expression string, and create another
- * <code>MethodExpression</code> whose expected param types match
- * those of a zero argument method. The usage requirements for both
- * of these <code>MethodExpression</code> instances are described in
- * {@link #processEvent}.</span></p>
- *
- * @param methodExpressionOneArg a <code>MethodExpression</code>
- * that points to a method that returns <code>void</code> and takes
- * a single argument of type {@link FacesEvent}.
- */
- protected MethodExpressionEventListener(MethodExpression methodExpressionOneArg) {
-
- super();
- this.methodExpressionOneArg = methodExpressionOneArg;
- FacesContext context = FacesContext.getCurrentInstance();
- ELContext elContext = context.getELContext();
- this.methodExpressionZeroArg =
context.getApplication().getExpressionFactory().createMethodExpression(
- elContext, methodExpressionOneArg.getExpressionString(), Void.class,
EVENT_LISTENER_ZERO_ARG_SIG);
- }
-
- /**
- * <p>Construct a {@link FacesListener} that contains a {@link
MethodExpression}.</p>
- *
- * @param methodExprOneArg
- * @param methodExprZeroArg
- */
- protected MethodExpressionEventListener(MethodExpression methodExprOneArg,
MethodExpression methodExprZeroArg) {
-
- super();
- this.methodExpressionOneArg = methodExprOneArg;
- this.methodExpressionZeroArg = methodExprZeroArg;
- }
-
- // ------------------------------------------------------- Event Method
-
- /**
- * <p><span class="changed_modified_2_0">Call</span>
through to the
- * {@link MethodExpression} passed in our constructor. <span
- * class="changed_added_2_0">First, try to invoke the
- * <code>MethodExpression</code> passed to the constructor of this
- * instance, passing the argument {@link FacesEvent} as the
- * argument. If a {@link MethodNotFoundException} is thrown, call
- * to the zero argument <code>MethodExpression</code> derived from
- * the <code>MethodExpression</code> passed to the constructor of
- * this instance. If that fails for any reason, throw an {@link
- * AbortProcessingException}, including the cause of the
- * failure.</span></p>
- *
- * @throws NullPointerException {@inheritDoc}
- * @throws AbortProcessingException {@inheritDoc}
- */
- public void processEvent(FacesEvent event) throws AbortProcessingException {
-
- if (event == null) {
- throw new NullPointerException();
- }
- FacesContext context = FacesContext.getCurrentInstance();
- ELContext elContext = context.getELContext();
- // PENDING: The corresponding code in MethodExpressionActionListener
- // has an elaborate message capture, logging, and rethrowing block.
- // Why not here?
- try {
- methodExpressionOneArg.invoke(elContext, new Object[] {event});
- } catch (MethodNotFoundException mnf) {
- if (null != methodExpressionZeroArg) {
-
- try {
- // try to invoke a no-arg version
- methodExpressionZeroArg.invoke(elContext, NO_PARAMS);
- } catch (ELException e) {
- throw new AbortProcessingException(e.getMessage(), e.getCause());
- }
- }
- } catch (ELException e) {
- throw new AbortProcessingException(e.getMessage(), e.getCause());
- }
- }
-
-
- // ------------------------------------------------ Methods from StateHolder
-
-
- /**
- * <p class="changed_modified_2_0">Both {@link MethodExpression}
- * instances described in the constructor must be saved.</p>
- */
- public Object saveState(FacesContext context) {
- if (context == null) {
- throw new NullPointerException();
- }
-
- return new Object[] {
- UIComponentBase.saveAttachedState(context, methodExpressionOneArg),
- UIComponentBase.saveAttachedState(context, methodExpressionZeroArg)
- };
- }
-
-
- /**
- * <p class="changed_modified_2_0">Both {@link MethodExpression}
- * instances described in the constructor must be restored.</p>
- */
- public void restoreState(FacesContext context, Object state) {
-
- if (context == null) {
- throw new NullPointerException();
- }
- if (state == null) {
- return;
- }
-
- methodExpressionOneArg = (MethodExpression) UIComponentBase
- .restoreAttachedState(context, ((Object[]) state)[0]);
- methodExpressionZeroArg = (MethodExpression) UIComponentBase
- .restoreAttachedState(context, ((Object[]) state)[1]);
- }
-
-
- public boolean isTransient() {
- return isTransient;
- }
-
- public void setTransient(boolean newTransientValue) {
- isTransient = newTransientValue;
- }
-}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ChangeExpandListenerHandler.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ChangeExpandListenerHandler.java 2010-09-03
08:39:33 UTC (rev 19107)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ChangeExpandListenerHandler.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -66,5 +66,10 @@
ChangeExpandSource source = (ChangeExpandSource) parent;
source.addChangeExpandListener(new LazyChangeExpandListener(this.listenerType,
expression));
}
+
+ @Override
+ public boolean isEventSource(UIComponent comp) {
+ return comp instanceof ChangeExpandSource;
+ }
}
Deleted:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java 2010-09-03
08:39:33 UTC (rev 19107)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/EventListenerHandler.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -1,145 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.view.facelets.html;
-
-import org.richfaces.component.AbstractCollapsiblePanel;
-
-import javax.el.ValueExpression;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-import javax.faces.view.EditableValueHolderAttachedObjectHandler;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.TagAttribute;
-import javax.faces.view.facelets.TagAttributeException;
-import javax.faces.view.facelets.TagConfig;
-import javax.faces.view.facelets.TagException;
-import javax.faces.view.facelets.TagHandler;
-import java.io.IOException;
-import java.io.Serializable;
-
-/**
- * @author akolonitsky
- * @since Aug 31, 2010
- */
-public abstract class EventListenerHandler extends TagHandler implements
EditableValueHolderAttachedObjectHandler {
-
- protected final TagAttribute binding;
-
- protected final String listenerType;
-
- public abstract static class LazyEventListener<L extends FacesListener>
implements FacesListener, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- protected final String type;
-
- protected final ValueExpression binding;
-
- protected LazyEventListener(String type, ValueExpression binding) {
- this.type = type;
- this.binding = binding;
- }
-
- public void processEvent(FacesEvent event) throws AbortProcessingException {
-
- FacesContext faces = FacesContext.getCurrentInstance();
- if (faces == null) {
- return;
- }
-
- L instance = null;
- if (this.binding != null) {
- instance = (L) binding.getValue(faces.getELContext());
- }
- if (instance == null && this.type != null) {
- try {
- instance = (L) forName(this.type).newInstance();
- } catch (Exception e) {
- throw new AbortProcessingException("Couldn't Lazily
instantiate EventListener", e);
- }
- if (this.binding != null) {
- binding.setValue(faces.getELContext(), instance);
- }
- }
-
- if (instance != null) {
- event.processListener(instance);
- }
- }
- }
-
- public EventListenerHandler(TagConfig config) {
- super(config);
- this.binding = this.getAttribute("binding");
- TagAttribute type = this.getAttribute("type");
- if (type != null) {
- if (type.isLiteral()) {
- try {
- forName(type.getValue());
- } catch (ClassNotFoundException e) {
- throw new TagAttributeException(type, "Couldn't qualify
EventListener", e);
- }
- } else {
- throw new TagAttributeException(type, "Must be a literal class name
of type EventListener");
- }
- this.listenerType = type.getValue();
- } else {
- this.listenerType = null;
- }
- }
-
- public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
-
- // only process if it's been created
- if (parent == null || !ComponentHandler.isNew(parent)) {
- return;
- }
-
- if (parent instanceof AbstractCollapsiblePanel) {
- applyAttachedObject(ctx.getFacesContext(), parent);
- } else if (UIComponent.isCompositeComponent(parent)) {
- // Allow the composite component to know about the target component.
- TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
- } else {
- throw new TagException(this.tag, "Parent is not of type
EditableValueHolder, type is: " + parent);
- }
- }
-
- public String getFor() {
- TagAttribute attr = this.getAttribute("for");
- return attr == null ? null : attr.getValue();
- }
-
- public static Class<?> forName(String name) throws ClassNotFoundException {
- if (null == name || "".equals(name)) {
- return null;
- }
-
- return Class.forName(name, false,
Thread.currentThread().getContextClassLoader());
- }
-}
-
-
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-09-03
08:39:33 UTC (rev 19107)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-09-03
08:56:24 UTC (rev 19108)
@@ -67,5 +67,10 @@
ItemChangeSource evh = (ItemChangeSource) parent;
evh.addItemChangeListener(new LazyItemChangeListener(this.listenerType,
valueExpr));
}
+
+ @Override
+ public boolean isEventSource(UIComponent comp) {
+ return comp instanceof ItemChangeSource;
+ }
}