Author: abelevich
Date: 2010-04-26 10:24:29 -0400 (Mon, 26 Apr 2010)
New Revision: 16808
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java
root/ui-sandbox/trunk/components/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js
Log:
add client script, client script encode
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java 2010-04-26
13:38:50 UTC (rev 16807)
+++
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java 2010-04-26
14:24:29 UTC (rev 16808)
@@ -1,7 +1,6 @@
package org.richfaces.renderkit;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,6 +16,9 @@
import javax.faces.render.RenderKitFactory;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.component.UIHashParameter;
import org.richfaces.component.behavior.ComponentControlBehavior;
@@ -34,11 +36,14 @@
private static final String FUNC_NAME =
"RichFaces.ui.ComponentControl.execute";
- private static final String API_FUNCTION = "operation";
+ private static final String REF_EVENT = "event";
+
+ private static final String REF_COMPONENT = "component";
- private static final String API_ARGUMENTS = "args";
-
-
+ private static final String PARAM_CALLBACK = "callback";
+
+ private static final String PARAM_TARGET = "target";
+
public static final String SEPARATOR = "\\.";
@@ -46,21 +51,34 @@
@Override
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
ComponentControlBehavior controlBehavior = (ComponentControlBehavior)behavior;
- Map<String, Object> parameters = new HashMap<String, Object>();
- //JSFunctionDefenition
- String target = controlBehavior.getTarget();
-
+
+ JSFunctionDefinition callback = new JSFunctionDefinition();
+ callback.addParameter(new JSReference(REF_EVENT));
+ callback.addParameter(new JSReference(REF_COMPONENT));
+
String apiFunctionName = controlBehavior.getOperation();
- parameters.put(API_FUNCTION, apiFunctionName);
+
+ StringBuffer script = new StringBuffer();
+
script.append(REF_COMPONENT).append("[").append(apiFunctionName).append("].").append("apply").append("(");
List<Object> apiFunctionParams = createSignature(controlBehavior);
- parameters.put(API_ARGUMENTS, apiFunctionParams.toArray());
-
+
script.append(REF_COMPONENT).append(",").append(ScriptUtils.toScript(apiFunctionParams.toArray())).append(");");
+ callback.addToBody(script);
+
+ String target = controlBehavior.getTarget();
+
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put(PARAM_CALLBACK, callback);
+ parameters.put(PARAM_TARGET, target);
+
JSFunction eventFunction = new JSFunction(FUNC_NAME);
- eventFunction.addParameter(target);
+ eventFunction.addParameter(new JSReference(REF_EVENT));
eventFunction.addParameter(parameters);
-
- return (eventFunction != null ? eventFunction.toScript() : null);
+
+ StringBuffer execution = new StringBuffer();
+ execution.append(eventFunction.toScript());
+ execution.append("; return false;");
+ return execution.toString();
}
protected List<Object> createSignature(ComponentControlBehavior behavior) {
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js
===================================================================
---
root/ui-sandbox/trunk/components/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js 2010-04-26
13:38:50 UTC (rev 16807)
+++
root/ui-sandbox/trunk/components/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js 2010-04-26
14:24:29 UTC (rev 16808)
@@ -1,19 +1,23 @@
-(function (jQuery, richfaces) {
+(function ($, richfaces) {
richfaces = richfaces || {};
richfaces.ui.ComponentControl = richfaces.ui.ComponentControl || {};
- jQuery.extend(richfaces.ui.ComponentControl, {
+ $.extend(richfaces.ui.ComponentControl, {
- execute: function(id, parameters) {
- richfaces.ui.ComponentControl.eachComponent();
-
+ execute: function(event, parameters) {
+ var target = parameters.target;
+ var callback = parameters.callback;
+
+ if(target && (callback && typeof callback == 'function'))
{
+ richfaces.ui.ComponentControl.eachComponent(event, target, callback);
+ }
},
- eachComponent : function(forAttr, callback) {
- jQuery(forAttr.replace(/:/g, "\\:").each(function() {
+ eachComponent : function(event, target, callback) {
+ $(target.replace(/:/g, "\\:")).each(function() {
if (this.component) {
- callback(this.component);
+ callback(event, this.component);
}
});
}