Author: abelevich
Date: 2010-04-28 13:38:19 -0400 (Wed, 28 Apr 2010)
New Revision: 16830
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/tag/BehaviorTagHandlerDelegate.java
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/taglib/ComponentControlHandler.java
Log:
fix and move nested component processing logic for the component control from
tagHandlerDelegate to ComponentControlHandler
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/tag/BehaviorTagHandlerDelegate.java
===================================================================
---
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/tag/BehaviorTagHandlerDelegate.java 2010-04-28
17:36:28 UTC (rev 16829)
+++
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/tag/BehaviorTagHandlerDelegate.java 2010-04-28
17:38:19 UTC (rev 16830)
@@ -1,130 +1,49 @@
package org.richfaces.tag;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIParameter;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
import javax.faces.view.AttachedObjectHandler;
-import javax.faces.view.facelets.ComponentConfig;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.CompositeFaceletHandler;
+import javax.faces.view.facelets.BehaviorHandler;
import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.FaceletHandler;
import javax.faces.view.facelets.MetaRuleset;
import javax.faces.view.facelets.TagHandlerDelegate;
-import org.richfaces.component.UIHashParameter;
-import org.richfaces.component.behavior.ComponentControlBehavior;
-
-
-public class BehaviorTagHandlerDelegate extends TagHandlerDelegate implements
AttachedObjectHandler{
-
- private TagHandlerDelegate tagHandlerDelegate;
+public class BehaviorTagHandlerDelegate extends TagHandlerDelegate implements
AttachedObjectHandler {
- private List<UIComponent> children;
-
- public BehaviorTagHandlerDelegate(TagHandlerDelegate tagHandlerDelegate) {
- this.tagHandlerDelegate = tagHandlerDelegate;
+ TagHandlerDelegate wrappedHandlerDelegate;
+
+ BehaviorHandler owner;
+
+ public BehaviorTagHandlerDelegate(BehaviorHandler owner, TagHandlerDelegate
wrappedHandlerDelegate) {
+ this.owner = owner;
+ this.wrappedHandlerDelegate = wrappedHandlerDelegate;
}
@Override
- public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
- this.tagHandlerDelegate.apply(ctx, parent);
+ public void apply(FaceletContext ctx, UIComponent comp) throws IOException {
+ wrappedHandlerDelegate.apply(ctx, comp);
}
-
- public void apply(FaceletContext ctx, UIComponent parent, FaceletHandler nextHandler)
throws IOException {
- apply(ctx, parent);
- processAttachedObject(ctx, parent, nextHandler);
- }
-
+
@Override
public MetaRuleset createMetaRuleset(Class type) {
- MetaRuleset metaRuleset = this.tagHandlerDelegate.createMetaRuleset(type);
+ MetaRuleset metaRuleset = wrappedHandlerDelegate.createMetaRuleset(type);
metaRuleset.addRule(new BehaviorRule());
return metaRuleset;
}
public void applyAttachedObject(FacesContext context, UIComponent parent) {
- if(tagHandlerDelegate instanceof AttachedObjectHandler) {
- ((AttachedObjectHandler)tagHandlerDelegate).applyAttachedObject(context,
parent);
+ if(wrappedHandlerDelegate instanceof AttachedObjectHandler) {
+ ((AttachedObjectHandler)wrappedHandlerDelegate).applyAttachedObject(context,
parent);
}
}
public String getFor() {
- String retValue = null;
- if(tagHandlerDelegate instanceof AttachedObjectHandler) {
- retValue = ((AttachedObjectHandler)tagHandlerDelegate).getFor();
+ if(wrappedHandlerDelegate instanceof AttachedObjectHandler) {
+ return ((AttachedObjectHandler)wrappedHandlerDelegate).getFor();
}
- return retValue;
+ return null;
}
-
-
- public void processNextHandler(FaceletContext ctx, FaceletHandler nextHandler,
UIComponent parent) throws IOException {
- if(nextHandler instanceof CompositeFaceletHandler) {
- FaceletHandler [] children =
((CompositeFaceletHandler)nextHandler).getHandlers();
- for (FaceletHandler handler: children) {
- collectParameters(ctx, handler, parent);
- }
- } else {
- collectParameters(ctx, nextHandler, parent);
- }
- }
-
- private void processAttachedObject(FaceletContext ctx, UIComponent parent,
FaceletHandler nextHandler) throws IOException{
- ClientBehaviorHolder holder = (ClientBehaviorHolder)parent;
- Map<String, List<ClientBehavior>> behaviors =
holder.getClientBehaviors();
- Set<Map.Entry<String,List<ClientBehavior>>> entries =
behaviors.entrySet();
- for(Map.Entry<String, List<ClientBehavior>>entry: entries) {
- for(ClientBehavior behavior: entry.getValue()) {
- if(behavior instanceof ComponentControlBehavior) {
- processNextHandler(ctx, nextHandler, parent);
- ((ComponentControlBehavior)
behavior).getChildren().addAll(getChildren());
- //reset collected children after save to the behavior;
- children = null;
- }
- }
- }
- }
-
- private void collectParameters(FaceletContext ctx, FaceletHandler handler,
UIComponent parent) throws IOException {
- if(handler instanceof ComponentHandler) {
- ComponentHandler componentHandler = (ComponentHandler) handler;
-
- ComponentConfig componentConfig = componentHandler.getComponentConfig();
- String componentType = componentConfig.getComponentType();
- if(isUIParameter(componentType)) {
-
- FacesContext facesContext = ctx.getFacesContext();
- UIComponent component =
(UIComponent)facesContext.getApplication().createComponent(facesContext, componentType,
null);
- if((component instanceof UIParameter) || (component instanceof
UIHashParameter)) {
- componentHandler.setAttributes(ctx, component);
- getChildren().add(component);
- }
-
- if(component instanceof UIHashParameter) {
- componentHandler.applyNextHandler(ctx, component);
- }
- }
- }
- }
-
- private boolean isUIParameter(String type) {
- return (UIParameter.COMPONENT_TYPE.equals(type) ||
UIHashParameter.COMPONENT_TYPE.equals(type));
- }
-
- public List<UIComponent> getChildren() {
- if(this.children == null) {
- this.children = new ArrayList<UIComponent>();
- }
- return this.children;
- }
-
}
Modified:
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/taglib/ComponentControlHandler.java
===================================================================
---
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/taglib/ComponentControlHandler.java 2010-04-28
17:36:28 UTC (rev 16829)
+++
root/ui-sandbox/trunk/components/componentcontrol/src/main/java/org/richfaces/taglib/ComponentControlHandler.java 2010-04-28
17:38:19 UTC (rev 16830)
@@ -1,40 +1,89 @@
package org.richfaces.taglib;
import java.io.IOException;
+import java.util.List;
+import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIParameter;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.FacesContext;
import javax.faces.view.facelets.BehaviorConfig;
-import javax.faces.view.facelets.BehaviorHandler;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.CompositeFaceletHandler;
import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.TagHandlerDelegate;
+import javax.faces.view.facelets.FaceletHandler;
-import org.richfaces.tag.BehaviorTagHandlerDelegate;
+import org.richfaces.component.UIHashParameter;
+import org.richfaces.component.behavior.ComponentControlBehavior;
+import org.richfaces.tag.CustomBehaviorHandler;
-public class ComponentControlHandler extends BehaviorHandler {
-
- private BehaviorTagHandlerDelegate helper;
+public class ComponentControlHandler extends CustomBehaviorHandler {
-
public ComponentControlHandler(BehaviorConfig config) {
super(config);
}
-
- public BehaviorTagHandlerDelegate getBehaviorTagHandlerDelegate() {
- return (BehaviorTagHandlerDelegate)getTagHandlerDelegate();
- }
-
+
@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
- getBehaviorTagHandlerDelegate().apply(ctx, parent, nextHandler);
+ super.apply(ctx, parent);
+ processNestedTags(ctx, parent);
}
-
- @Override
- protected TagHandlerDelegate getTagHandlerDelegate() {
- if(helper == null){
- helper = new BehaviorTagHandlerDelegate(super.getTagHandlerDelegate());
+
+
+ private void processNestedTags(FaceletContext ctx, UIComponent parent) throws
IOException {
+ if(nextHandler instanceof CompositeFaceletHandler) {
+ FaceletHandler [] children =
((CompositeFaceletHandler)nextHandler).getHandlers();
+ for (FaceletHandler handler: children) {
+ processNextHandler(ctx, handler, parent);
+ }
+ } else {
+ processNextHandler(ctx, nextHandler, parent);
}
- return helper;
}
+ private void processNextHandler(FaceletContext ctx, FaceletHandler handler,
UIComponent parent) throws IOException {
+ if(handler instanceof ComponentHandler) {
+ ComponentHandler componentHandler = (ComponentHandler) handler;
+
+ ComponentConfig componentConfig = componentHandler.getComponentConfig();
+ String componentType = componentConfig.getComponentType();
+
+ if(isUIParameter(componentType)) {
+ FacesContext facesContext = ctx.getFacesContext();
+
+ UIComponent component =
(UIComponent)facesContext.getApplication().createComponent(facesContext, componentType,
null);
+ componentHandler.setAttributes(ctx, component);
+
+ if(parent instanceof ClientBehaviorHolder) {
+ ClientBehaviorHolder clientBehaviorHolder =
((ClientBehaviorHolder)parent);
+ Map<String, List<ClientBehavior>> clientBehaviors =
clientBehaviorHolder.getClientBehaviors();
+
+ String eventName = getEventName();
+
+ if(eventName == null) {
+ eventName = clientBehaviorHolder.getDefaultEventName();
+ }
+
+ if(eventName != null) {
+ List<ClientBehavior> eventClientBehaviors =
clientBehaviors.get(eventName);
+ for(ClientBehavior clientBehavior: eventClientBehaviors) {
+ if(clientBehavior instanceof ComponentControlBehavior) {
+
((ComponentControlBehavior)clientBehavior).getChildren().add(component);
+ }
+ }
+ }
+ }
+
+ componentHandler.applyNextHandler(ctx, component);
+ }
+ }
+ }
+
+ private boolean isUIParameter(String type) {
+ return (UIParameter.COMPONENT_TYPE.equals(type) ||
UIHashParameter.COMPONENT_TYPE.equals(type));
+ }
}