Author: nbelaevski
Date: 2009-08-27 08:57:54 -0400 (Thu, 27 Aug 2009)
New Revision: 15341
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxEventOptions.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.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:
Ajax functions parameters optimization
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxEventOptions.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxEventOptions.java 2009-08-27
12:15:13 UTC (rev 15340)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxEventOptions.java 2009-08-27
12:57:54 UTC (rev 15341)
@@ -61,8 +61,15 @@
options.remove(optionName);
}
- @SuppressWarnings("unchecked")
+ public boolean hasParameters() {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> parameters = (Map<String, Object>)
options.get(PARAMETERS);
+ return parameters != null && !parameters.isEmpty();
+ }
+
+ //TODO: optimize rendered data
public Map<String, Object> getParameters() {
+ @SuppressWarnings("unchecked")
Map<String, Object> parameters = (Map<String, Object>)
options.get(PARAMETERS);
if (parameters == null) {
parameters = new LinkedHashMap<String, Object>();
@@ -72,9 +79,9 @@
return parameters;
}
- @SuppressWarnings("unchecked")
public Object getParameter(String parameterName) {
Object result = null;
+ @SuppressWarnings("unchecked")
Map<String, Object> parameters = (Map<String, Object>)
options.get(PARAMETERS);
if (parameters != null) {
result = parameters.get(parameterName);
@@ -87,8 +94,8 @@
getParameters().put(parameterName, parameterValue);
}
- @SuppressWarnings("unchecked")
public void removeParameter(String parameterName) {
+ @SuppressWarnings("unchecked")
Map<String, Object> parameters = (Map<String, Object>)
options.get(PARAMETERS);
if (parameters != null) {
parameters.remove(parameterName);
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
12:15:13 UTC (rev 15340)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-27
12:57:54 UTC (rev 15341)
@@ -327,9 +327,11 @@
if (ajaxStatusName != null && ajaxStatusName.length() != 0) {
ajaxEventOptions.set(STATUS_ATTR_NAME, ajaxStatusName);
}
-
- ajaxEventOptions.getParameters().putAll(parametersMap);
+ if (!parametersMap.isEmpty()) {
+ ajaxEventOptions.getParameters().putAll(parametersMap);
+ }
+
return ajaxEventOptions;
}
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
12:15:13 UTC (rev 15340)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2009-08-27
12:57:54 UTC (rev 15341)
@@ -34,6 +34,7 @@
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;
@@ -84,7 +85,10 @@
handlersChain.addBehaviors(context, "click");
JSFunction ajaxFunction = buildAjaxFunction(context, component, AJAX_FUNCTION_NAME);
- ajaxFunction.addParameter(buildEventOptions(context, component));
+ AjaxEventOptions eventOptions = buildEventOptions(context, component);
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
String handlerScript = handlersChain.toScript();
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
12:15:13 UTC (rev 15340)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java 2009-08-27
12:57:54 UTC (rev 15341)
@@ -55,32 +55,37 @@
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
context, component, AjaxRendererUtils.AJAX_FUNCTION_NAME);
AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(context, component);
- ajaxFunction.addParameter(options);
- Map<String, Object> parameters = options.getParameters();
-// if (null == parameters) {
-// parameters = new HashMap<String, Object>();
-// options.put("parameters", parameters);
-// }
- // Fill parameters.
- for (Iterator<UIComponent> it = component.getChildren().iterator();
it.hasNext();) {
- UIComponent child = it.next();
- if (child instanceof UIParameter) {
- UIParameter parameter = ((UIParameter) child);
- String name = parameter.getName();
- func.addParameter(name);
- // Put parameter name to AJAX.Submit parameter, with default value.
- JSReference reference = new JSReference(name);
- if (null != parameter.getValue()) {
- reference = new JSReference(name + "||"
- + ScriptUtils.toScript(parameters.get(name)));
+ if (options.hasParameters()) {
+ Map<String, Object> parameters = options.getParameters();
+// if (null == parameters) {
+// parameters = new HashMap<String, Object>();
+// options.put("parameters", parameters);
+// }
+ // Fill parameters.
+ for (Iterator<UIComponent> it = component.getChildren().iterator();
it.hasNext();) {
+ UIComponent child = it.next();
+ if (child instanceof UIParameter) {
+ UIParameter parameter = ((UIParameter) child);
+ String name = parameter.getName();
+ func.addParameter(name);
+ // Put parameter name to AJAX.Submit parameter, with default value.
+ JSReference reference = new JSReference(name);
+ if (null != parameter.getValue()) {
+ reference = new JSReference(name + "||"
+ + ScriptUtils.toScript(parameters.get(name)));
+ }
+ // Replace parameter value to reference.
+ parameters.put(name, reference);
}
- // Replace parameter value to reference.
- parameters.put(name, reference);
}
}
+ if (!options.isEmpty()) {
+ ajaxFunction.addParameter(options);
+ }
+
//TODO - added in 4.0 - ?
func.addParameter(JSReference.EVENT);
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
12:15:13 UTC (rev 15340)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2009-08-27
12:57:54 UTC (rev 15341)
@@ -35,6 +35,7 @@
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;
@@ -106,7 +107,10 @@
if (!handlersChain.hasSubmittingBehavior()) {
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(context, push,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
- ajaxFunction.addParameter(AjaxRendererUtils.buildEventOptions(context, push));
+ AjaxEventOptions eventOptions = AjaxRendererUtils.buildEventOptions(context, push);
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
}