Author: nbelaevski
Date: 2009-08-26 21:24:26 -0400 (Wed, 26 Aug 2009)
New Revision: 15329
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/renderkit/AjaxBehaviorRenderer.java
root/ui/trunk/components/core/src/main/java/org/richfaces/component/html/HtmlPush.java
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
Log:
Behaviors rendering code refactoring
Added AJAX event behaviors to a4j:push
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -23,14 +23,11 @@
import java.io.IOException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -38,12 +35,6 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
-import javax.faces.component.UIParameter;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.component.behavior.ClientBehaviorHint;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -55,7 +46,6 @@
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxLoadBundleComponent;
import org.ajax4jsf.component.AjaxViewRoot;
-import org.ajax4jsf.component.JavaScriptParameter;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
@@ -253,42 +243,6 @@
}
- private static void appendParameters(FacesContext context, UIComponent component,
Map<String, Object> parameters) {
- if (component.getChildCount() > 0) {
- for (UIComponent child : component.getChildren()) {
- if (child instanceof UIParameter) {
- UIParameter parameter = (UIParameter) child;
-
- String name = parameter.getName();
- Object value = parameter.getValue();
-
- if (null == name) {
- throw new IllegalArgumentException(Messages.getMessage(
- Messages.UNNAMED_PARAMETER_ERROR, component
- .getClientId(context)));
- }
-
- boolean escape = true;
- if (child instanceof JavaScriptParameter) {
- JavaScriptParameter actionParam = (JavaScriptParameter) child;
- escape = !actionParam.isNoEscape();
- }
- if (escape) {
- if(value == null) {
- value = "";
- }
- parameters.put(name, value);
- } else {
- parameters.put(name, new JSReference(value.toString()));
- // if(it.hasNext()){onEvent.append(',');};
- // renderAjaxLinkParameter( name,
- // value, onClick, jsForm, nestingForm);
- }
- }
- }
- }
- }
-
private static enum EventOptionsData {
begin {
@Override
@@ -352,66 +306,64 @@
public abstract String getAttributeValue(AjaxClientBehavior behavior);
}
- public static AjaxEventOptions buildEventOptions(FacesContext facesContext,
AjaxClientBehavior ajaxBehavior, UIComponent component) {
+ public static AjaxEventOptions buildEventOptions(FacesContext facesContext, UIComponent
component) {
+ return buildEventOptions(facesContext, component, null);
+ }
+
+ public static AjaxEventOptions buildEventOptions(FacesContext facesContext, UIComponent
component, AjaxClientBehavior ajaxBehavior) {
AjaxEventOptions ajaxEventOptions = new AjaxEventOptions();
- Map<String, Object> parametersMap = new LinkedHashMap<String, Object>();
+ Map<String, Object> parametersMap =
rendererUtils.createParametersMap(facesContext, component);
String ajaxStatusName = getAjaxStatus(component);
if(ajaxBehavior != null) {
ajaxStatusName = ajaxBehavior.getStatusId() != null ? ajaxBehavior.getStatusId() :
ajaxStatusName;
- appenAjaxBehaviorParams(facesContext, ajaxBehavior, ajaxEventOptions);
+ appenAjaxBehaviorOptions(facesContext, ajaxBehavior, ajaxEventOptions);
} else {
- appendBehaviorParams(facesContext, component, ajaxEventOptions, parametersMap);
+ appendComponentOptions(facesContext, component, ajaxEventOptions, parametersMap);
}
if (ajaxStatusName != null && ajaxStatusName.length() != 0) {
ajaxEventOptions.set(STATUS_ATTR_NAME, ajaxStatusName);
}
- appendParameters(facesContext, component, parametersMap);
ajaxEventOptions.getParameters().putAll(parametersMap);
return ajaxEventOptions;
}
- private static void appenAjaxBehaviorParams(FacesContext context, AjaxClientBehavior
behavior, AjaxEventOptions ajaxEventOptions) {
+ /**
+ * @param eventHandlerValue
+ * @return
+ */
+ private static boolean isNotEmpty(String value) {
+ return value != null && value.length() != 0;
+ }
+
+ private static void appenAjaxBehaviorOptions(FacesContext context, AjaxClientBehavior
behavior, AjaxEventOptions ajaxEventOptions) {
for(BehaviorEventOptionsData optionsData : BehaviorEventOptionsData.values()) {
String eventHandlerValue = optionsData.getAttributeValue(behavior);
- if(isNonEmpty(eventHandlerValue)) {
+ if (isNotEmpty(eventHandlerValue)) {
ajaxEventOptions.set(optionsData.toString(), eventHandlerValue);
}
}
}
- private static void appendBehaviorParams(FacesContext facesContext, UIComponent
component, AjaxEventOptions ajaxEventOptions, Map<String, Object> parametersMap)
{
- Collection<Parameter> behaviorParametersList = null;
- Map<String, List<ClientBehavior>> behaviorsMap = Collections.EMPTY_MAP; /*
null object */
+ private static void appendComponentOptions(FacesContext facesContext, UIComponent
component,
+ AjaxEventOptions ajaxEventOptions, Map<String, Object> parametersMap) {
- if (component instanceof ClientBehaviorHolder) {
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
- behaviorsMap = clientBehaviorHolder.getClientBehaviors();
- }
-
for (EventOptionsData eventOptionsData : EventOptionsData.values()) {
String behaviorName = eventOptionsData.toString();
- ClientBehaviorContext behaviorContext = null;
- List<ClientBehavior> behaviorsList = behaviorsMap.get(behaviorName);
- if (behaviorsList != null) {
- if (behaviorParametersList == null) {
- behaviorParametersList = getBehaviorParametersList(facesContext, component,
parametersMap);
- }
-
- behaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext,
component,
- behaviorName, null, behaviorParametersList);
- }
- String behaviorsChain = createBehaviorsChain(facesContext,
eventOptionsData.getAttributeValue(component),
- behaviorsList, behaviorContext, false);
+ HandlersChain handlersChain = new HandlersChain(component);
+ String inlineHandler = eventOptionsData.getAttributeValue(component);
+ handlersChain.addInlineHandlerAsValue(facesContext, inlineHandler);
+ handlersChain.addBehaviors(facesContext, behaviorName);
+ String handlerScript = handlersChain.toScript();
- if (isNonEmpty(behaviorsChain)) {
- ajaxEventOptions.set(behaviorName, behaviorsChain);
+ if (isNotEmpty(handlerScript)) {
+ ajaxEventOptions.set(behaviorName, handlerScript);
}
}
}
@@ -603,14 +555,14 @@
/**
* Create call to Ajax Submit function with first two parameters
- *
- * @param uiComponent
* @param facesContext
+ * @param uiComponent
* @param functionName
+ *
* @return
*/
- public static JSFunction buildAjaxFunction(UIComponent uiComponent,
- FacesContext facesContext, String functionName) {
+ public static JSFunction buildAjaxFunction(FacesContext facesContext,
+ UIComponent uiComponent, String functionName) {
JSFunction ajaxFunction = new JSFunction(functionName);
ajaxFunction.addParameter(uiComponent.getClientId(facesContext));
ajaxFunction.addParameter(JSReference.EVENT);
@@ -1198,104 +1150,4 @@
AjaxContext.getCurrentInstance(facesContext).addRegionsFromComponent(component);
}
-
- private static final boolean isNonEmpty(String s) {
- return s!= null && s.length() != 0;
- }
-
- public static String createBehaviorsChain(FacesContext facesContext, UIComponent
component, String eventHandlerAttribute,
- String behaviorName, boolean needsSubmittingBehavior) {
-
- List<ClientBehavior> behaviors = null;
-
- String eventHandler = (String) component.getAttributes().get(eventHandlerAttribute);
- if (component instanceof ClientBehaviorHolder) {
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
- Map<String, List<ClientBehavior>> clientBehaviorsMap =
clientBehaviorHolder.getClientBehaviors();
- if (clientBehaviorsMap != null) {
- behaviors = clientBehaviorsMap.get(behaviorName);
- }
- }
-
- ClientBehaviorContext behaviorContext = null;
- if (behaviors != null || needsSubmittingBehavior) {
- Collection<Parameter> parametersList =
AjaxRendererUtils.getBehaviorParametersList(facesContext, component);
- behaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext,
component,
- behaviorName, null, parametersList);
- }
-
- if (isNonEmpty(eventHandler) || behaviors != null || needsSubmittingBehavior) {
- return AjaxRendererUtils.createBehaviorsChain(facesContext, eventHandler, behaviors,
behaviorContext, needsSubmittingBehavior);
- } else {
- return null;
- }
- }
-
- public static String createBehaviorsChain(FacesContext facesContext, String
eventHandlerValue, List<ClientBehavior> behaviors,
- ClientBehaviorContext behaviorContext, boolean needsSubmittingBehavior) {
-
- String result = null;
-
- //TODO: performance optimizization
- List<String> handlers = new ArrayList<String>(2);
- if (isNonEmpty(eventHandlerValue)) {
- handlers.add(eventHandlerValue);
- }
-
- boolean hasSubmittingBehavior = false;
- Map<String, Object> parametersMap = new LinkedHashMap<String, Object>();
-
- if (behaviors != null) {
- for (ClientBehavior clientBehavior : behaviors) {
- String behaviorScript = clientBehavior.getScript(behaviorContext);
- if (isNonEmpty(behaviorScript)) {
- if (clientBehavior.getHints().contains(ClientBehaviorHint.SUBMITTING)) {
- hasSubmittingBehavior = true;
- }
-
- handlers.add(behaviorScript);
- }
- }
- }
-
- if (!hasSubmittingBehavior && needsSubmittingBehavior) {
- JSFunction jsFunction = new JSFunction(AJAX_FUNCTION_NAME, JSReference.THIS,
JSReference.EVENT);
- if (parametersMap != null && !parametersMap.isEmpty()) {
- jsFunction.addParameter(parametersMap);
- }
- handlers.add(jsFunction.toScript());
- }
-
- if (!handlers.isEmpty()) {
- if (handlers.size() == 1) {
- result = handlers.get(0);
- } else {
- JSFunction jsFunction = new JSFunction("jsf.util.chain", JSReference.THIS,
JSReference.EVENT);
- for (String handler : handlers) {
- jsFunction.addParameter(handler);
- }
- result = jsFunction.toScript();
- }
- }
-
- return result;
- }
-
- private static Collection<ClientBehaviorContext.Parameter>
getBehaviorParametersList(FacesContext context, UIComponent component,
- Map<String, Object> parametersMap) {
-
- List<Parameter> result = new
ArrayList<ClientBehaviorContext.Parameter>(parametersMap.size());
- for (Map.Entry<String, Object> entry : parametersMap.entrySet()) {
- result.add(new ClientBehaviorContext.Parameter(entry.getKey(), entry.getValue()));
- }
- return result;
- }
-
- public static Collection<ClientBehaviorContext.Parameter>
getBehaviorParametersList(FacesContext context, UIComponent component) {
- Map<String, Object> parametersMap = new LinkedHashMap<String, Object>();
- //TODO: merge to a single method
- appendParameters(context, component, parametersMap);
-
- return getBehaviorParametersList(context, component, parametersMap);
- }
}
Added: root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -0,0 +1,179 @@
+/**
+ * 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.ajax4jsf.renderkit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHint;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public final class HandlersChain {
+
+ private static final Logger log = RichfacesLogger.RENDERKIT.getLogger();
+
+ private boolean hasSubmittingBehavior = false;
+
+ private UIComponent component;
+
+ private Collection<Parameter> parameters;
+
+ private boolean skipSubmittingBehaviors = false;
+
+ private boolean behaviorsHandled = false;
+
+ //TODO: review for optimization
+ private List<String> handlers = new ArrayList<String>(2);
+
+ private final boolean isNotEmpty(String s) {
+ return s != null && s.length() != 0;
+ }
+
+
+ public HandlersChain(UIComponent component) {
+ this.component = component;
+ }
+
+ public HandlersChain(UIComponent component, Collection<Parameter> parameters) {
+ this.component = component;
+ this.parameters = parameters;
+ }
+
+ private final List<ClientBehavior> getBehaviorsList(String behaviorName) {
+ behaviorsHandled = true;
+
+ List<ClientBehavior> behaviors = null;
+ if (component instanceof ClientBehaviorHolder) {
+ ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
+ Map<String, List<ClientBehavior>> clientBehaviorsMap =
clientBehaviorHolder.getClientBehaviors();
+ if (clientBehaviorsMap != null) {
+ behaviors = clientBehaviorsMap.get(behaviorName);
+ }
+ }
+
+ return behaviors;
+ }
+
+ private Collection<Parameter> getParameters(FacesContext context) {
+ if (parameters == null) {
+ RendererUtils rendererUtils = RendererUtils.getInstance();
+ Map<String, Object> parametersMap = rendererUtils.createParametersMap(context,
component);
+ parameters = createParametersList(parametersMap);
+ }
+
+ return parameters;
+ }
+
+
+ public boolean hasSubmittingBehavior() {
+ return hasSubmittingBehavior;
+ }
+
+ public void addInlineHandlerAsValue(FacesContext context, String handlerValue) {
+ if (isNotEmpty(handlerValue)) {
+ handlers.add(handlerValue);
+ }
+ }
+
+ public void addInlineHandlerFromAttribute(FacesContext context, String attributeName) {
+ addInlineHandlerAsValue(context, (String)
component.getAttributes().get(attributeName));
+ }
+
+ public void addBehaviors(FacesContext context, String behaviorName) {
+ List<ClientBehavior> behaviorsList = getBehaviorsList(behaviorName);
+ if (behaviorsList != null) {
+ ClientBehaviorContext behaviorContext =
ClientBehaviorContext.createClientBehaviorContext(
+ context, component, behaviorName, null, getParameters(context));
+
+ for (ClientBehavior clientBehavior : behaviorsList) {
+ String behaviorScript = clientBehavior.getScript(behaviorContext);
+ if (isNotEmpty(behaviorScript)) {
+ if (clientBehavior.getHints().contains(ClientBehaviorHint.SUBMITTING)) {
+ if (skipSubmittingBehaviors) {
+
+ //TODO: discuss this - it is not ok to skip submitting behaviors completely
+ log.info("Submitting behavior '" + behaviorScript + "' has
been skipped");
+ continue;
+ }
+
+ hasSubmittingBehavior = true;
+ }
+
+ handlers.add(behaviorScript);
+ }
+ }
+ }
+ }
+
+ public String toScript() {
+ String result = null;
+ if (!handlers.isEmpty()) {
+ if (handlers.size() == 1) {
+ result = handlers.get(0);
+ } else {
+ JSFunction jsFunction = new JSFunction("jsf.util.chain", JSReference.THIS,
JSReference.EVENT);
+ for (String handler : handlers) {
+ jsFunction.addParameter(handler);
+ }
+ result = jsFunction.toScript();
+ }
+ }
+
+ return result;
+ }
+
+ public static List<Parameter> createParametersList(Map<String, Object>
parametersMap) {
+ List<Parameter> parameters = new
ArrayList<Parameter>(parametersMap.size());
+ for (Entry<String, Object> entry: parametersMap.entrySet()) {
+ parameters.add(new Parameter(entry.getKey(), entry.getValue()));
+ }
+
+ return parameters;
+ }
+
+ /**
+ * @param ignoreSubmittingBehaviors the ignoreSubmittingBehaviors to set
+ */
+ public void setSkipSubmittingBehaviors() {
+ assert (!behaviorsHandled) : "Some behaviors were already processed by this
chain!";
+
+ this.skipSubmittingBehaviors = true;
+ }
+
+}
\ No newline at end of file
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -28,8 +28,8 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -39,10 +39,9 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
+import javax.faces.component.UIParameter;
import javax.faces.component.UIViewRoot;
import javax.faces.component.ValueHolder;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
import javax.faces.context.FacesContext;
@@ -50,8 +49,10 @@
import javax.faces.convert.Converter;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.JavaScriptParameter;
import org.ajax4jsf.javascript.JSEncoder;
import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.util.HtmlDimensions;
/**
@@ -347,6 +348,47 @@
}
}
+ public Map<String, Object> createParametersMap(FacesContext context, UIComponent
component) {
+ Map<String, Object> parameters = new LinkedHashMap<String, Object>();
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ if (child instanceof UIParameter) {
+ UIParameter parameter = (UIParameter) child;
+
+ String name = parameter.getName();
+ Object value = parameter.getValue();
+
+ if (null == name) {
+ throw new IllegalArgumentException(Messages.getMessage(
+ Messages.UNNAMED_PARAMETER_ERROR, component
+ .getClientId(context)));
+ }
+
+ boolean escape = true;
+ if (child instanceof JavaScriptParameter) {
+ JavaScriptParameter actionParam = (JavaScriptParameter) child;
+ escape = !actionParam.isNoEscape();
+ }
+ if (escape) {
+ if(value == null) {
+ value = "";
+ }
+ } else {
+ value = new JSReference(value.toString());
+ // if(it.hasNext()){onEvent.append(',');};
+ // renderAjaxLinkParameter( name,
+ // value, onClick, jsForm, nestingForm);
+ }
+
+ parameters.put(name, value);
+ }
+ }
+ }
+
+ return parameters;
+ }
+
public void encodeBehaviors(FacesContext context, ClientBehaviorHolder behaviorHolder,
String defaultHtmlEventName, String[] attributesExclusions) throws IOException {
@@ -360,8 +402,8 @@
if (eventNames != null) {
UIComponent component = (UIComponent) behaviorHolder;
ResponseWriter writer = context.getResponseWriter();
- Map<String, List<ClientBehavior>> clientBehaviors =
behaviorHolder.getClientBehaviors();
- Collection<Parameter> behaviorParametersList =
AjaxRendererUtils.getBehaviorParametersList(context, component);
+ Collection<Parameter> parametersList =
+ HandlersChain.createParametersList(createParametersMap(context, component));
for (String behaviorEventName : eventNames) {
if (behaviorEventName.equals(defaultEventName)) {
@@ -369,27 +411,14 @@
}
String htmlEventName = "on" + behaviorEventName;
- List<ClientBehavior> behaviorsList = clientBehaviors.get(behaviorEventName);
- if (behaviorsList == null && behaviorEventName.equals(defaultHtmlEventName)
&&
- defaultEventName != null) {
-
- behaviorEventName = defaultEventName;
- behaviorsList = clientBehaviors.get(behaviorEventName);
- }
+ HandlersChain handlersChain = new HandlersChain(component, parametersList);
+ handlersChain.addInlineHandlerFromAttribute(context, htmlEventName);
+ handlersChain.addBehaviors(context, behaviorEventName);
+ String handlerScript = handlersChain.toScript();
- ClientBehaviorContext clientBehaviorContext = null;
- if (behaviorsList != null) {
- clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(context,
component, behaviorEventName,
- null, behaviorParametersList);
+ if (!isEmpty(handlerScript)) {
+ writer.writeAttribute(htmlEventName, handlerScript, htmlEventName);
}
-
- String eventHandlerValue = (String) component.getAttributes().get(htmlEventName);
- if (!isEmpty(eventHandlerValue) || behaviorsList != null) {
- String behaviorsChain = AjaxRendererUtils.createBehaviorsChain(context,
eventHandlerValue,
- behaviorsList, clientBehaviorContext, false);
-
- writer.writeAttribute(htmlEventName, behaviorsChain, htmlEventName);
- }
}
}
}
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/renderkit/AjaxBehaviorRenderer.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/renderkit/AjaxBehaviorRenderer.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/renderkit/AjaxBehaviorRenderer.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -85,7 +85,7 @@
UIComponent parent = bContext.getComponent();
FacesContext context = bContext.getFacesContext();
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(parent, context,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(context, parent,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
AjaxEventOptions options = buildOptions(context, bContext, behavior);
ajaxFunction.addParameter(options);
@@ -96,7 +96,7 @@
public AjaxEventOptions buildOptions(FacesContext context, ClientBehaviorContext
bContext, AjaxClientBehavior behavior) {
UIComponent parent = bContext.getComponent();
String eventName = bContext.getEventName();
- AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(context, behavior,
parent);
+ AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(context, parent,
behavior);
options.setParameter(PartialViewContextImpl.BEHAVIOR_EVENT_PARAMETER, eventName);
options.setParameter(PartialViewContextFactoryImpl.RICHFACES_AJAX,
parent.getClientId());
Modified:
root/ui/trunk/components/core/src/main/java/org/richfaces/component/html/HtmlPush.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/component/html/HtmlPush.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/component/html/HtmlPush.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -26,8 +26,10 @@
*
*/
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashSet;
import javax.faces.component.behavior.ClientBehaviorHolder;
@@ -35,18 +37,19 @@
public class HtmlPush extends UIPush implements ClientBehaviorHolder {
- public final static String COMPONENT_FAMILY = "org.richfaces.Push";
+ public final static String COMPONENT_FAMILY = "org.richfaces.Push";
- public final static String COMPONENT_TYPE = "org.richfaces.Push";
+ public final static String COMPONENT_TYPE = "org.richfaces.Push";
public static final String ON_DATA_AVAILABLE = "ondataavailable";
public static final String DATA_AVAILABLE = "dataAvailable";
- private static final Collection<String> EVENT_NAMES =
Collections.singleton(DATA_AVAILABLE);
+ private static final Collection<String> EVENT_NAMES =
Collections.unmodifiableCollection(
+ new LinkedHashSet<String>(Arrays.asList(DATA_AVAILABLE, "begin",
"beforedomupdate", "complete")));
private static enum PropertyKeys {
- ondataavailable
+ ondataavailable, onbegin, onbeforedomupdate, oncomplete
}
public HtmlPush(){
@@ -74,4 +77,28 @@
public void setOndataavailable(String ondataavailable) {
getStateHelper().put(PropertyKeys.ondataavailable, ondataavailable);
}
+
+ public String getOnbegin() {
+ return (String) getStateHelper().eval(PropertyKeys.onbegin);
+ }
+
+ public void setOnbegin(String onbegin) {
+ getStateHelper().put(PropertyKeys.onbegin, onbegin);
+ }
+
+ public String getOnbeforedomupdate() {
+ return (String) getStateHelper().eval(PropertyKeys.onbeforedomupdate);
+ }
+
+ public void setOnbeforedomupdate(String onbeforedomupdate) {
+ getStateHelper().put(PropertyKeys.onbeforedomupdate, onbeforedomupdate);
+ }
+
+ public String getOncomplete() {
+ return (String) getStateHelper().eval(PropertyKeys.oncomplete);
+ }
+
+ public void setOncomplete(String oncomplete) {
+ getStateHelper().put(PropertyKeys.oncomplete, oncomplete);
+ }
}
Modified:
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -21,6 +21,10 @@
package org.richfaces.renderkit;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.AJAX_FUNCTION_NAME;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildAjaxFunction;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildEventOptions;
+
import java.util.Map;
import javax.faces.application.ResourceDependencies;
@@ -29,7 +33,8 @@
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
@@ -73,7 +78,20 @@
public String getOnClick(FacesContext context, UIComponent component) {
StringBuffer onClick = new StringBuffer();
if (!getUtils().isBooleanAttribute(component, "disabled")) {
- onClick.append(AjaxRendererUtils.createBehaviorsChain(context, component,
"onclick", "click" , true));
+ HandlersChain handlersChain = new HandlersChain(component);
+ handlersChain.setSkipSubmittingBehaviors();
+ handlersChain.addInlineHandlerFromAttribute(context, "onclick");
+ handlersChain.addBehaviors(context, "click");
+
+ JSFunction ajaxFunction = buildAjaxFunction(context, component, AJAX_FUNCTION_NAME);
+ ajaxFunction.addParameter(buildEventOptions(context, component));
+ handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
+
+ String handlerScript = handlersChain.toScript();
+ if (handlerScript != null) {
+ onClick.append(handlerScript);
+ }
+
if (!"reset".equals(component.getAttributes().get("type"))) {
onClick.append(";return false;");
}
Modified:
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -53,8 +53,8 @@
//func.setName(component.getName());
// Create AJAX Submit function.
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
- component, context, AjaxRendererUtils.AJAX_FUNCTION_NAME);
- AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(context, null,
component);
+ context, component, AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(context, component);
ajaxFunction.addParameter(options);
Map<String, Object> parameters = options.getParameters();
Modified:
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2009-08-27
00:44:00 UTC (rev 15328)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2009-08-27
01:24:26 UTC (rev 15329)
@@ -36,6 +36,7 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIPush;
@@ -99,12 +100,21 @@
options.put("pushId", push.getListenerId(context));
options.put("clientId", component.getClientId(context));
- String behaviorsChain = AjaxRendererUtils.createBehaviorsChain(context, push,
HtmlPush.ON_DATA_AVAILABLE,
- HtmlPush.DATA_AVAILABLE, true);
+ HandlersChain handlersChain = new HandlersChain(push);
+ handlersChain.addInlineHandlerFromAttribute(context, HtmlPush.ON_DATA_AVAILABLE);
+ handlersChain.addBehaviors(context, HtmlPush.DATA_AVAILABLE);
- if (behaviorsChain != null) {
+ if (!handlersChain.hasSubmittingBehavior()) {
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(context, push,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ ajaxFunction.addParameter(AjaxRendererUtils.buildEventOptions(context, push));
+ handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
+ }
+
+ String handler = handlersChain.toScript();
+
+ if (handler != null) {
JSFunctionDefinition dataAvailableHandler = new
JSFunctionDefinition(JSReference.EVENT);
- dataAvailableHandler.addToBody(behaviorsChain);
+ dataAvailableHandler.addToBody(handler);
options.put(HtmlPush.ON_DATA_AVAILABLE, dataAvailableHandler);
}
function.addParameter(options);