Author: nbelaevski
Date: 2010-05-31 19:24:26 -0400 (Mon, 31 May 2010)
New Revision: 17437
Modified:
root/ui/misc/trunk/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java
root/ui/misc/trunk/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js
Log:
https://jira.jboss.org/browse/RF-8720
Modified:
root/ui/misc/trunk/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java
===================================================================
---
root/ui/misc/trunk/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java 2010-05-31
23:22:36 UTC (rev 17436)
+++
root/ui/misc/trunk/componentcontrol/src/main/java/org/richfaces/renderkit/ComponentControlBehaviorRenderer.java 2010-05-31
23:24:26 UTC (rev 17437)
@@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
@@ -33,6 +34,7 @@
import javax.faces.component.UIParameter;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.context.FacesContext;
import javax.faces.render.ClientBehaviorRenderer;
import javax.faces.render.FacesBehaviorRenderer;
import javax.faces.render.RenderKitFactory;
@@ -41,6 +43,7 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.UIHashParameter;
import org.richfaces.component.behavior.ComponentControlBehavior;
@@ -68,8 +71,14 @@
private static final String PARAM_SELECTOR = "selector";
+ private static final Pattern COMMA_SEPARATED_STRING =
Pattern.compile("\\s*,\\s*");
+
+ private final RendererUtils utils = RendererUtils.getInstance();
+
@Override
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
+ FacesContext facesContext = behaviorContext.getFacesContext();
+
ComponentControlBehavior controlBehavior = (ComponentControlBehavior) behavior;
JSFunctionDefinition callback = new JSFunctionDefinition();
@@ -87,12 +96,12 @@
script.append(REF_COMPONENT).append(",").append(ScriptUtils.toScript(apiFunctionParams.toArray())).append(");");
callback.addToBody(script);
- String target = controlBehavior.getTarget();
+ String targetSourceString = controlBehavior.getTarget();
String selector = controlBehavior.getSelector();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(PARAM_CALLBACK, callback);
- parameters.put(PARAM_TARGET, target);
+ parameters.put(PARAM_TARGET, resolveTargets(facesContext, targetSourceString));
parameters.put(PARAM_SELECTOR, selector);
// execution function
@@ -138,4 +147,34 @@
}
return elements;
}
+
+ protected String[] resolveTargets(FacesContext context, String targetSourceString) {
+ if (targetSourceString == null) {
+ return null;
+ }
+
+ //TODO nick - externalize to utility method
+ String[] split = COMMA_SEPARATED_STRING.split(targetSourceString);
+ UIComponent contextComponent = UIComponent.getCurrentComponent(context);
+ if (contextComponent == null) {
+ contextComponent = context.getViewRoot();
+ }
+
+ List<String> resultHolder = new ArrayList<String>(split.length);
+
+ for (String target : split) {
+ UIComponent targetComponent = utils.findComponentFor(contextComponent,
target);
+
+ String targetClientId;
+ if (targetComponent != null) {
+ targetClientId = targetComponent.getClientId(context);
+ } else {
+ targetClientId = target;
+ }
+
+ resultHolder.add(targetClientId);
+ }
+
+ return resultHolder.toArray(new String[resultHolder.size()]);
+ }
}
Modified:
root/ui/misc/trunk/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js
===================================================================
---
root/ui/misc/trunk/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js 2010-05-31
23:22:36 UTC (rev 17436)
+++
root/ui/misc/trunk/componentcontrol/src/main/resources/META-INF/resources/script/component-control.js 2010-05-31
23:24:26 UTC (rev 17437)
@@ -7,15 +7,14 @@
$.extend(richfaces.ui.ComponentControl, {
execute: function(event, parameters) {
- var target = parameters.target;
+ var targetList = parameters.target;
var selector = parameters.selector;
var callback = parameters.callback;
- if(target) {
- var ids = target.split(',');
- for (var i = 0; i < ids.length; i++) {
- var component = document.getElementById(ids[i]);
- if(component) {
+ if (targetList) {
+ for (var i = 0; i < targetList.length; i++) {
+ var component = document.getElementById(targetList[i]);
+ if (component) {
richfaces.ui.ComponentControl.invokeOnComponent(event, component, callback);
}
}