Author: nbelaevski
Date: 2010-07-23 12:17:45 -0400 (Fri, 23 Jul 2010)
New Revision: 18219
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
Log:
HandlersChain refactoring
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -313,11 +313,11 @@
private static void appendComponentOptions(FacesContext facesContext, UIComponent
component,
AjaxEventOptions ajaxEventOptions) {
String behaviorName = "begin";
- HandlersChain handlersChain = new HandlersChain(component);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component);
String inlineHandler = getAjaxOnBegin(component);
- handlersChain.addInlineHandlerAsValue(facesContext, inlineHandler);
- handlersChain.addBehaviors(facesContext, behaviorName);
+ handlersChain.addInlineHandlerAsValue(inlineHandler);
+ handlersChain.addBehaviors(behaviorName);
String handlerScript = handlersChain.toScript();
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -21,9 +21,16 @@
package org.ajax4jsf.renderkit;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
+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.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;
@@ -31,12 +38,10 @@
import javax.faces.component.behavior.ClientBehaviorHint;
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -49,24 +54,30 @@
// TODO: review for optimization
private List<String> handlers = new ArrayList<String>(2);
+
+ private FacesContext facesContext;
private UIComponent component;
private Collection<Parameter> parameters;
- public HandlersChain(UIComponent component) {
+ public HandlersChain(FacesContext facesContext, UIComponent component) {
+ this.facesContext = facesContext;
this.component = component;
}
- public HandlersChain(UIComponent component, boolean includeClientId) {
+ public HandlersChain(FacesContext facesContext, UIComponent component, boolean
includeClientId) {
+ this.facesContext = facesContext;
this.component = component;
this.includeClientId = includeClientId;
}
- public HandlersChain(UIComponent component, Collection<Parameter> parameters)
{
+ public HandlersChain(FacesContext facesContext, UIComponent component,
Collection<Parameter> parameters) {
+ this.facesContext = facesContext;
this.component = component;
this.parameters = parameters;
}
- public HandlersChain(UIComponent component, Collection<Parameter> parameters,
boolean includeClientId) {
+ public HandlersChain(FacesContext facesContext, UIComponent component,
Collection<Parameter> parameters, boolean includeClientId) {
+ this.facesContext = facesContext;
this.component = component;
this.parameters = parameters;
this.includeClientId = includeClientId;
@@ -91,10 +102,10 @@
return behaviors;
}
- private Collection<Parameter> getParameters(FacesContext context) {
+ private Collection<Parameter> getParameters() {
if (parameters == null) {
RendererUtils rendererUtils = RendererUtils.getInstance();
- Map<String, Object> parametersMap =
rendererUtils.createParametersMap(context, component);
+ Map<String, Object> parametersMap =
rendererUtils.createParametersMap(facesContext, component);
parameters = createParametersList(parametersMap);
}
@@ -106,21 +117,21 @@
return hasSubmittingBehavior;
}
- public void addInlineHandlerAsValue(FacesContext context, String handlerValue) {
+ public void addInlineHandlerAsValue(String handlerValue) {
if (isNotEmpty(handlerValue)) {
handlers.add(handlerValue);
}
}
- public void addInlineHandlerFromAttribute(FacesContext context, String attributeName)
{
- addInlineHandlerAsValue(context, (String)
component.getAttributes().get(attributeName));
+ public void addInlineHandlerFromAttribute(String attributeName) {
+ addInlineHandlerAsValue((String) component.getAttributes().get(attributeName));
}
- public void addBehaviors(FacesContext context, String domEventName) {
- addBehaviors(context, domEventName, null);
+ public void addBehaviors(String domEventName) {
+ addBehaviors(domEventName, null);
}
- public void addBehaviors(FacesContext context, String domEventName, String
logicalEventName) {
+ public void addBehaviors(String domEventName, String logicalEventName) {
String name = domEventName;
List<ClientBehavior> behaviorsList = getBehaviorsList(domEventName);
@@ -133,9 +144,9 @@
return;
}
- ClientBehaviorContext behaviorContext =
ClientBehaviorContext.createClientBehaviorContext(context, component,
- name, includeClientId ? component.getClientId(context) : null,
- getParameters(context));
+ ClientBehaviorContext behaviorContext =
ClientBehaviorContext.createClientBehaviorContext(facesContext, component,
+ name, includeClientId ? component.getClientId(facesContext) : null,
+ getParameters());
for (ClientBehavior clientBehavior : behaviorsList) {
String behaviorScript = clientBehavior.getScript(behaviorContext);
@@ -150,6 +161,21 @@
}
}
+ public void addAjaxSubmitFunction() {
+ if (!this.hasSubmittingBehavior()) {
+ hasSubmittingBehavior = true;
+
+ JSFunction ajaxFunction = buildAjaxFunction(facesContext, component,
AJAX_FUNCTION_NAME);
+ AjaxEventOptions eventOptions = buildEventOptions(facesContext, component);
+
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
+
+ this.addInlineHandlerAsValue(ajaxFunction.toScript());
+ }
+ }
+
public String toScript() {
String result = null;
@@ -179,4 +205,5 @@
return parameters;
}
+
}
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -263,10 +263,10 @@
String htmlEventName = "on" + behaviorEventName;
if ((attributesExclusions == null) ||
(Arrays.binarySearch(attributesExclusions, htmlEventName) < 0)) {
- HandlersChain handlersChain = new HandlersChain(component,
parametersList);
+ HandlersChain handlersChain = new HandlersChain(context, component,
parametersList);
- handlersChain.addInlineHandlerFromAttribute(context, htmlEventName);
- handlersChain.addBehaviors(context, behaviorEventName);
+ handlersChain.addInlineHandlerFromAttribute(htmlEventName);
+ handlersChain.addBehaviors(behaviorEventName);
String handlerScript = handlersChain.toScript();
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -23,10 +23,6 @@
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;
@@ -35,8 +31,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.log.RichfacesLogger;
@@ -89,22 +83,12 @@
StringBuffer onClick = new StringBuffer();
if (!getUtils().isBooleanAttribute(component, "disabled")) {
- HandlersChain handlersChain = new HandlersChain(component);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component);
- handlersChain.addInlineHandlerFromAttribute(context, "onclick");
- handlersChain.addBehaviors(context, "click", "action");
+ handlersChain.addInlineHandlerFromAttribute("onclick");
+ handlersChain.addBehaviors("click", "action");
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = buildAjaxFunction(context, component,
AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions = buildEventOptions(context, component);
-
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
-
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handlerScript = handlersChain.toScript();
if (handlerScript != null) {
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -21,27 +21,26 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
+
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPoll;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionEvent;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author shura
*/
@@ -81,20 +80,11 @@
Integer interval = new Integer(poll.getInterval());
options.put("pollinterval", interval);
options.put("pollId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(poll);
- handlersChain.addInlineHandlerFromAttribute(context, AbstractPoll.ON_TIMER);
- handlersChain.addBehaviors(context, AbstractPoll.TIMER);
+ HandlersChain handlersChain = new HandlersChain(facesContext, poll);
+ handlersChain.addInlineHandlerFromAttribute(AbstractPoll.ON_TIMER);
+ handlersChain.addBehaviors(AbstractPoll.TIMER);
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
- context, poll, AjaxRendererUtils.AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions =
AjaxRendererUtils.buildEventOptions(context, poll);
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handler = handlersChain.toScript();
if (handler != null) {
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -35,8 +35,6 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
@@ -107,20 +105,11 @@
options.put("pushId", push.getListenerId(context));
options.put("clientId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(push);
- handlersChain.addInlineHandlerFromAttribute(context,
AbstractPush.ON_DATA_AVAILABLE);
- handlersChain.addBehaviors(context, AbstractPush.DATA_AVAILABLE);
+ HandlersChain handlersChain = new HandlersChain(facesContext, push);
+ handlersChain.addInlineHandlerFromAttribute(AbstractPush.ON_DATA_AVAILABLE);
+ handlersChain.addBehaviors(AbstractPush.DATA_AVAILABLE);
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = AjaxRendererUtils
- .buildAjaxFunction(context, push,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions =
AjaxRendererUtils.buildEventOptions(context, push);
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handler = handlersChain.toScript();
if (handler != null) {
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-07-23
14:17:53 UTC (rev 18218)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
@@ -202,9 +202,9 @@
Map<String, Object> attributes = ajaxStatus.getAttributes();
for (String eventName : EVENT_NAMES) {
String eventAttribute = "on" + eventName;
- HandlersChain handlersChain = new HandlersChain(component, true);
- handlersChain.addInlineHandlerFromAttribute(context, eventAttribute);
- handlersChain.addBehaviors(context, eventName);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component,
true);
+ handlersChain.addInlineHandlerFromAttribute(eventAttribute);
+ handlersChain.addBehaviors(eventName);
rendererUtils.addToScriptHash(options, eventAttribute,
handlersChain.toScript(), null,
ScriptHashVariableWrapper.EVENT_HANDLER);