Author: nbelaevski
Date: 2010-05-28 08:32:32 -0400 (Fri, 28 May 2010)
New Revision: 17354
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/LazyActionListener.java
Removed:
root/ui/core/trunk/api/src/main/resources/META-INF/a4j_ext.taglib.xml
Modified:
root/examples/core-demo/trunk/src/main/webapp/actionListener.xhtml
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/ActionListenerHandler.java
Log:
https://jira.jboss.org/browse/RF-8444
Modified: root/examples/core-demo/trunk/src/main/webapp/actionListener.xhtml
===================================================================
--- root/examples/core-demo/trunk/src/main/webapp/actionListener.xhtml 2010-05-28 12:14:43
UTC (rev 17353)
+++ root/examples/core-demo/trunk/src/main/webapp/actionListener.xhtml 2010-05-28 12:32:32
UTC (rev 17354)
@@ -5,7 +5,6 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:a4j_ext="http://richfaces.org/a4j_ext"
xmlns:demo="http://java.sun.com/jsf/composite/demo">
<f:view>
<h:head>
@@ -16,22 +15,22 @@
<h:panelGrid columns="1">
<h:commandButton value="Invoke listener by type">
- <a4j_ext:actionListener
type="org.richfaces.demo.ActionListenerBean$ActionListenerImpl" />
+ <a4j:actionListener
type="org.richfaces.demo.ActionListenerBean$ActionListenerImpl" />
<f:ajax render="messages" />
</h:commandButton>
<h:commandButton value="Invoke listener by binding">
- <a4j_ext:actionListener binding="#{actionListenerBean.actionListener}"
/>
+ <a4j:actionListener binding="#{actionListenerBean.actionListener}"
/>
<f:ajax render="messages" />
</h:commandButton>
<h:commandButton value="Invoke listener method">
- <a4j_ext:actionListener
listener="#{actionListenerBean.handleActionMethod}" />
+ <a4j:actionListener listener="#{actionListenerBean.handleActionMethod}"
/>
<f:ajax render="messages" />
</h:commandButton>
<demo:actionComposite render=":form:messages" value="Invoke
listener method in composite component">
- <a4j_ext:actionListener for="button"
listener="#{actionListenerBean.handleActionMethodComposite}" />
+ <a4j:actionListener for="button"
listener="#{actionListenerBean.handleActionMethodComposite}" />
</demo:actionComposite>
</h:panelGrid>
</h:form>
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/ActionListenerHandler.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/ActionListenerHandler.java 2010-05-28
12:14:43 UTC (rev 17353)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/ActionListenerHandler.java 2010-05-28
12:32:32 UTC (rev 17354)
@@ -22,14 +22,12 @@
package org.richfaces.view.facelets.html;
import java.io.IOException;
-import java.io.Serializable;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.ActionSource;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.event.MethodExpressionActionListener;
@@ -53,53 +51,7 @@
private String listenerType;
private TagAttribute listenerMethod;
-
- private static final class LazyActionListener implements ActionListener, Serializable
{
- /**
- *
- */
- private static final long serialVersionUID = 6303879250524609909L;
-
- private final String type;
-
- private final ValueExpression binding;
-
- public LazyActionListener(String type, ValueExpression binding) {
- this.type = type;
- this.binding = binding;
- }
-
- public void processAction(ActionEvent event) throws AbortProcessingException {
- ActionListener instance = null;
- FacesContext faces = FacesContext.getCurrentInstance();
- if (faces == null) {
- return;
- }
-
- if (this.binding != null) {
- instance = (ActionListener) binding.getValue(faces.getELContext());
- }
-
- if (instance == null && this.type != null) {
- try {
- instance = TagHandlerUtils.loadClass(this.type,
ActionListener.class).newInstance();
- } catch (Exception e) {
- throw new AbortProcessingException(
- "Couldn't lazily instantiate ActionListener", e);
- }
-
- if (this.binding != null) {
- binding.setValue(faces.getELContext(), instance);
- }
- }
-
- if (instance != null) {
- instance.processAction(event);
- }
- }
- }
-
public ActionListenerHandler(TagConfig config) {
super(config);
@@ -114,21 +66,19 @@
try {
TagHandlerUtils.loadClass(type.getValue(), ActionListener.class);
} catch (ClassNotFoundException e) {
- throw new TagAttributeException(type,
- "Couldn't qualify ActionListener", e);
+ throw new TagAttributeException(type, "Couldn't qualify
ActionListener", e);
} catch (ClassCastException e) {
- throw new TagAttributeException(type,
- "Qualified class is not ActionListener", e);
+ throw new TagAttributeException(type, "Qualified class is not
ActionListener", e);
}
}
-
+
this.listenerType = type.getValue();
} else {
this.listenerType = null;
}
-
+
this.listenerMethod = this.getAttribute("listener");
-
+
if (this.listenerMethod != null && this.binding != null) {
throw new TagException(this.tag, "Attributes 'listener' and
'binding' cannot be used simultaneously");
}
@@ -142,15 +92,15 @@
if (!(parent instanceof ActionSource)) {
throw new TagException(this.tag, "Parent is not of type ActionSource,
type is: " + parent);
}
-
+
ActionSource as = (ActionSource) parent;
-
+
FaceletContext ctx = (FaceletContext)
context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
if (this.listenerMethod != null) {
- MethodExpression listenerMethodExpression = this.listenerMethod.
- getMethodExpression(ctx, Void.TYPE, new Class<?>[] {
ActionEvent.class });
-
+ MethodExpression listenerMethodExpression =
this.listenerMethod.getMethodExpression(ctx, Void.TYPE,
+ new Class<?>[] { ActionEvent.class });
+
as.addActionListener(new
MethodExpressionActionListener(listenerMethodExpression));
} else {
ValueExpression b = null;
@@ -177,7 +127,7 @@
if (null == parent || !(ComponentHandler.isNew(parent))) {
return;
}
-
+
if (UIComponent.isCompositeComponent(parent)) {
if (null == getFor()) {
throw new TagException(this.tag,
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/LazyActionListener.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/LazyActionListener.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/LazyActionListener.java 2010-05-28
12:32:32 UTC (rev 17354)
@@ -0,0 +1,89 @@
+/*
+ * 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.io.Serializable;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+
+import org.richfaces.cdk.annotations.Event;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@Event(listener = ActionListener.class, source =
"org.richfaces.event.DummyActionListenerSource",
+ tag = {
+ @Tag(name = "actionListener", handler =
"org.richfaces.view.facelets.html.ActionListenerHandler",
+ generate = false, type = TagType.Facelets)
+ }
+)
+class LazyActionListener implements ActionListener, Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6303879250524609909L;
+
+ private final String type;
+
+ private final ValueExpression binding;
+
+ public LazyActionListener(String type, ValueExpression binding) {
+ this.type = type;
+ this.binding = binding;
+ }
+
+ public void processAction(ActionEvent event) throws AbortProcessingException {
+ ActionListener instance = null;
+ FacesContext faces = FacesContext.getCurrentInstance();
+ if (faces == null) {
+ return;
+ }
+
+ if (this.binding != null) {
+ instance = (ActionListener) binding.getValue(faces.getELContext());
+ }
+
+ if (instance == null && this.type != null) {
+ try {
+ instance = TagHandlerUtils.loadClass(this.type,
ActionListener.class).newInstance();
+ } catch (Exception e) {
+ throw new AbortProcessingException("Couldn't lazily instantiate
ActionListener", e);
+ }
+
+ if (this.binding != null) {
+ binding.setValue(faces.getELContext(), instance);
+ }
+ }
+
+ if (instance != null) {
+ instance.processAction(event);
+ }
+ }
+}
Deleted: root/ui/core/trunk/api/src/main/resources/META-INF/a4j_ext.taglib.xml
===================================================================
--- root/ui/core/trunk/api/src/main/resources/META-INF/a4j_ext.taglib.xml 2010-05-28
12:14:43 UTC (rev 17353)
+++ root/ui/core/trunk/api/src/main/resources/META-INF/a4j_ext.taglib.xml 2010-05-28
12:32:32 UTC (rev 17354)
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
- version="2.0" id="a4j_ext">
- <
namespace>http://richfaces.org/a4j_ext</namespace>
- <tag>
- <tag-name>actionListener</tag-name>
- <handler-class>org.richfaces.view.facelets.html.ActionListenerHandler</handler-class>
- <attribute>
- <description>
- Value binding expression that evaluates to an object that implements
- javax.faces.event.ActionListener.
- </description>
- <name>binding</name>
- <type>javax.faces.event.ActionListener</type>
- </attribute>
- <attribute>
- <description>
- If present, this attribute refers to the value of one of the exposed attached objects
within
- the composite component inside of which this tag is nested.
- </description>
- <name>for</name>
- <type>java.lang.String</type>
- </attribute>
- <attribute>
- <description>
- Method expression referencing a method that will be called when an ActionEvent has
been broadcast
- for the listener. Shouldn't be used simultaneously with 'binding' or
'type' attributes.
- </description>
- <name>listener</name>
- <type>javax.el.MethodExpression</type>
- </attribute>
- <attribute>
- <description>
- Fully qualified Java class name of an ActionListener to be created and registered.
- </description>
- <name>type</name>
- <type>java.lang.String</type>
- </attribute>
- </tag>
-</facelet-taglib>