Author: nbelaevski
Date: 2010-02-21 18:19:48 -0500 (Sun, 21 Feb 2010)
New Revision: 16479
Modified:
root/framework/trunk/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
root/framework/trunk/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
root/framework/trunk/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
Log:
TODOs & fixes for CDK
Removed renderChild() from RendererBase
https://jira.jboss.org/jira/browse/RF-8310
Modified:
root/framework/trunk/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
root/framework/trunk/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-02-21
23:15:30 UTC (rev 16478)
+++
root/framework/trunk/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-02-21
23:19:48 UTC (rev 16479)
@@ -35,6 +35,7 @@
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.component.behavior.ClientBehaviorHint;
import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -47,6 +48,16 @@
/**
*
*/
+ static final String BEHAVIOR_SOURCE_ID = "javax.faces.source";
+
+ /**
+ *
+ */
+ static final String BEHAVIOR_EVENT_NAME = "javax.faces.behavior.event";
+
+ /**
+ *
+ */
private static final String XHTML_ATTRIBUTE_PREFIX = "xml:";
/**
@@ -65,6 +76,8 @@
private static final String[] XHTML_ATTRIBUTE_NAMES = { "lang" };
+ private static final String DISABLED_ATTRIBUTE_NAME = "disabled";
+
private RenderKitUtils() {
// utility constructor
}
@@ -80,10 +93,23 @@
return result;
}
+ static boolean isDisabled(UIComponent component) {
+ Object disabledAttributeValue =
component.getAttributes().get(DISABLED_ATTRIBUTE_NAME);
+ if (disabledAttributeValue == null) {
+ return false;
+ }
+
+ if (disabledAttributeValue instanceof Boolean) {
+ return Boolean.TRUE.equals(disabledAttributeValue);
+ }
+
+ return Boolean.valueOf(disabledAttributeValue.toString());
+ }
+
static String escape(String s) {
StringBuilder sb = new StringBuilder(s.length());
int start = 0;
- int end = s.length();
+ int end;
while ((end = s.indexOf('\'', start)) >= 0) {
sb.append(s, start, end);
@@ -274,6 +300,7 @@
public static void renderPassThroughAttributesOptimized(FacesContext context,
UIComponent component,
Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
+ boolean disabled = isDisabled(component);
Set<String> handledAttributes = new
HashSet<String>(knownAttributesMap.size());
Object attributesThatAreSetObject =
component.getAttributes().get(ATTRIBUTES_THAT_ARE_SET);
if (attributesThatAreSetObject instanceof Collection<?>) {
@@ -289,7 +316,10 @@
if (knownAttribute != null) {
handledAttributes.add(knownAttribute.getHtmlAttributeName());
- // TODO check for disabled component
+ if (disabled && knownAttribute.getEventNames() != null) {
+ continue;
+ }
+
renderAttributeAndBehaviors(context, component, knownAttribute);
}
}
@@ -312,8 +342,48 @@
public static void renderPassThroughAttributes(FacesContext context, UIComponent
component,
Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
+ boolean disabled = isDisabled(component);
+
for (ComponentAttribute knownAttribute : knownAttributesMap.values()) {
+ if (disabled && knownAttribute.getEventNames() != null) {
+ continue;
+ }
+
renderAttributeAndBehaviors(context, component, knownAttribute);
}
}
+
+ public static void decodeBehaviors(FacesContext context, UIComponent component) {
+ if (!(component instanceof ClientBehaviorHolder)) {
+ return;
+ }
+
+ ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
+ Map<String, List<ClientBehavior>> behaviors =
holder.getClientBehaviors();
+
+ if (behaviors == null || behaviors.isEmpty()) {
+ return;
+ }
+
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, String> parametersMap =
externalContext.getRequestParameterMap();
+ String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);
+
+ if (behaviorEvent == null) {
+ return;
+ }
+
+ List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
+ String behaviorSource = parametersMap.get(BEHAVIOR_SOURCE_ID);
+ String clientId = component.getClientId(context);
+
+ if (behaviorSource != null && behaviorSource.equals(clientId)) {
+ if (behaviorsForEvent != null) {
+ for (ClientBehavior behavior : behaviorsForEvent) {
+ behavior.decode(context, component);
+ }
+ }
+ }
+ }
+
}
Modified:
root/framework/trunk/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
===================================================================
---
root/framework/trunk/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-02-21
23:15:30 UTC (rev 16478)
+++
root/framework/trunk/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-02-21
23:19:48 UTC (rev 16479)
@@ -23,23 +23,29 @@
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.same;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import javax.faces.component.UIComponent;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.component.behavior.ClientBehaviorHint;
import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@@ -56,21 +62,42 @@
*/
public class RenderKitUtilsTest {
+ /**
+ *
+ */
+ private static final String CLIENT_ID = "submittedId";
+
private MockFacesEnvironment facesEnvironment;
private ResponseWriter responseWriter;
private FacesContext facesContext;
+ private ExternalContext externalContext;
+
+ private Map<String, Object> componentAttributes;
+
+ private Map<String, List<ClientBehavior>> behaviorsMap;
+
+ private Map<String, ComponentAttribute> knownAttributes;
+
+ private List<Object> createdMocks;
+
@Before
public void setUp() throws Exception {
- facesEnvironment = FacesMock.createMockEnvironment();
- facesEnvironment.resetToNice();
+ facesEnvironment = FacesMock.createMockEnvironment().withExternalContext();
+
facesContext = facesEnvironment.getFacesContext();
-
+ externalContext = facesEnvironment.getExternalContext();
+
responseWriter = FacesMock.createMock(ResponseWriter.class);
- expect(facesContext.getResponseWriter()).andReturn(responseWriter).anyTimes();
-
expect(responseWriter.getContentType()).andReturn("application/xhtml+xml").anyTimes();
+ expect(facesContext.getResponseWriter()).andStubReturn(responseWriter);
+
expect(responseWriter.getContentType()).andStubReturn("application/xhtml+xml");
+
+ componentAttributes = new HashMap<String, Object>();
+ behaviorsMap = new HashMap<String, List<ClientBehavior>>();
+ knownAttributes = new TreeMap<String, ComponentAttribute>();
+ createdMocks = new ArrayList<Object>();
}
@After
@@ -78,8 +105,53 @@
this.facesEnvironment = null;
this.responseWriter = null;
this.facesContext = null;
+ this.externalContext = null;
+ this.componentAttributes = null;
+ this.behaviorsMap = null;
+ this.knownAttributes = null;
+ this.createdMocks = null;
}
+ private void replay(Object... objects) {
+ FacesMock.replay(facesEnvironment, responseWriter);
+ for (Object object : createdMocks) {
+ FacesMock.replay(object);
+ }
+ for (Object object : objects) {
+ FacesMock.replay(object);
+ }
+ }
+
+ private void verify(Object... objects) {
+ FacesMock.verify(facesEnvironment, responseWriter);
+ for (Object object : createdMocks) {
+ FacesMock.verify(object);
+ }
+ for (Object object : objects) {
+ FacesMock.verify(object);
+ }
+ }
+
+ private UIComponent createMockComponent() {
+ UIComponent component = FacesMock.createMock(UIComponent.class);
+ expect(component.getAttributes()).andStubReturn(componentAttributes);
+ expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
+ createdMocks.add(component);
+ return component;
+ }
+
+ private ClientBehaviorHolder createMockClientBehaviorHolder() {
+ UIComponent component = FacesMock.createMock(MockClientBehaviorHolder.class);
+ expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
+ expect(component.getAttributes()).andStubReturn(componentAttributes);
+ ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) component;
+ expect(behaviorHolder.getClientBehaviors()).andStubReturn(behaviorsMap);
+ expect(behaviorHolder.getEventNames()).andStubReturn(
+ Arrays.asList("click", "action", "mousemove",
"keypress", "blur", "contextmenu"));
+ createdMocks.add(behaviorHolder);
+ return behaviorHolder;
+ }
+
@Test
public void testEscape() throws Exception {
assertEquals("", RenderKitUtils.escape(""));
@@ -156,7 +228,6 @@
@Test
public void testRenderPassThroughAttributes() throws Exception {
- Map<String, ComponentAttribute> knownAttributes = new HashMap<String,
ComponentAttribute>();
knownAttributes.put("disabled", new
ComponentAttribute("disabled"));
knownAttributes.put("checked", new
ComponentAttribute("checked"));
knownAttributes.put("style", new
ComponentAttribute("style"));
@@ -164,7 +235,6 @@
knownAttributes.put("lang", new ComponentAttribute("lang"));
knownAttributes.put("class", new
ComponentAttribute("class").setComponentAttributeName("styleClass"));
- Map<String, Object> componentAttributes = new HashMap<String,
Object>();
componentAttributes.put("disabled", Boolean.TRUE);
componentAttributes.put("checked", Boolean.FALSE);
componentAttributes.put("style", "color:red");
@@ -173,8 +243,7 @@
componentAttributes.put("lang", "ru");
componentAttributes.put("styleClass", "rich-component");
- UIComponent component = FacesMock.createMock(UIComponent.class);
- expect(component.getAttributes()).andReturn(componentAttributes).anyTimes();
+ UIComponent component = createMockComponent();
responseWriter.writeAttribute(eq("disabled"), eq(Boolean.TRUE),
EasyMock.<String>isNull());
// checked attribute shouldn't be rendered - it's 'false'
@@ -184,25 +253,25 @@
responseWriter.writeAttribute(eq("xml:lang"), eq("ru"),
EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("class"),
eq("rich-component"), EasyMock.<String>isNull());
- FacesMock.replay(facesEnvironment, component, responseWriter);
+ replay();
RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- FacesMock.verify(facesEnvironment, component, responseWriter);
+ verify();
}
private ClientBehavior createClientBehavior(String handlerData,
Set<ClientBehaviorHint> hints) {
ClientBehavior behavior = FacesMock.createMock(ClientBehavior.class);
- expect(behavior.getScript(EasyMock.<ClientBehaviorContext>
notNull())).andReturn(
- MessageFormat.format("prompt({0})", handlerData)).anyTimes();
+ expect(behavior.getScript(EasyMock.<ClientBehaviorContext>
notNull())).andStubReturn(
+ MessageFormat.format("prompt({0})", handlerData));
- expect(behavior.getHints()).andReturn(hints).anyTimes();
+ expect(behavior.getHints()).andStubReturn(hints);
+ createdMocks.add(behavior);
return behavior;
}
@Test
public void testBehaviors() throws Exception {
- Map<String, ComponentAttribute> knownAttributes = new HashMap<String,
ComponentAttribute>();
knownAttributes.put("onclick", new
ComponentAttribute("onclick")
.setEventNames(new String[] { "click", "action" }));
knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
@@ -212,7 +281,6 @@
knownAttributes.put("oncontextmenu", new
ComponentAttribute("oncontextmenu")
.setEventNames(new String[] { "contextmenu" }));
- Map<String, Object> componentAttributes = new HashMap<String,
Object>();
componentAttributes.put("onkeypress", "alert(keypress)");
componentAttributes.put("onmousemove", "alert(mousemove)");
componentAttributes.put("onclick", "alert(click)");
@@ -220,8 +288,6 @@
Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
Set<ClientBehaviorHint> submittingHintsSet =
EnumSet.of(ClientBehaviorHint.SUBMITTING);
- Map<String, List<ClientBehavior>> behaviorsMap = new
HashMap<String, List<ClientBehavior>>();
-
ClientBehavior keypressBehavior = createClientBehavior("keypress",
emptyHintsSet);
ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
ClientBehavior actionBehavior2 = createClientBehavior("action2",
submittingHintsSet);
@@ -232,12 +298,8 @@
behaviorsMap.put("action", Arrays.asList(actionBehavior1,
actionBehavior2, actionBehavior3));
behaviorsMap.put("contextmenu", Arrays.asList(contextmenuBehavior));
- UIComponent component = FacesMock.createMock(MockClientBehaviorHolder.class);
- expect(component.getAttributes()).andReturn(componentAttributes).anyTimes();
- ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) component;
- expect(behaviorHolder.getClientBehaviors()).andReturn(behaviorsMap).anyTimes();
- expect(behaviorHolder.getEventNames()).andReturn(
- Arrays.asList("click", "action", "mousemove",
"keypress", "blur", "contextmenu")).anyTimes();
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
responseWriter.writeAttribute(eq("onkeypress"),
eq("jsf.util.chain('alert(keypress)','prompt(keypress)')"),
EasyMock.<String>isNull());
@@ -246,12 +308,189 @@
responseWriter.writeAttribute(eq("onmousemove"),
eq("alert(mousemove)"), EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("oncontextmenu"),
eq("prompt(contextmenu)"), EasyMock.<String>isNull());
- FacesMock.replay(component, facesEnvironment, responseWriter, keypressBehavior,
actionBehavior1,
- actionBehavior2, actionBehavior3, contextmenuBehavior);
+ replay();
RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- FacesMock.verify(component, facesEnvironment, responseWriter, keypressBehavior,
actionBehavior1,
- actionBehavior2, actionBehavior3, contextmenuBehavior);
+ verify();
}
+
+ private UIComponent setupBehaviorsTestForDisabledComponent() throws IOException {
+ knownAttributes.put("style", new
ComponentAttribute("style"));
+ knownAttributes.put("onclick", new
ComponentAttribute("onclick")
+ .setEventNames(new String[] { "click", "action" }));
+ knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
+ .setEventNames(new String[] { "mousemove" }));
+
+ componentAttributes.put("onmousemove", "alert(mousemove)");
+ componentAttributes.put("onclick", "alert(click)");
+ componentAttributes.put("style", "color:green");
+
+ Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
+
+ ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
+ behaviorsMap.put("action", Arrays.asList(actionBehavior1));
+
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
+ return component;
+ }
+
+ @Test
+ public void testBehaviorsForDisabledComponent() throws Exception {
+ componentAttributes.put("disabled", Boolean.TRUE);
+ UIComponent component = setupBehaviorsTestForDisabledComponent();
+
+ responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
+
+ replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+
+ verify();
+ }
+
+ @Test
+ public void testBehaviorsForNonDisabledComponent() throws Exception {
+ componentAttributes.put("disabled", Boolean.FALSE);
+ UIComponent component = setupBehaviorsTestForDisabledComponent();
+
+ responseWriter.writeAttribute(eq("onclick"),
eq("jsf.util.chain('alert(click)','prompt(action1)')"),
+ EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onmousemove"),
+ eq("alert(mousemove)"), EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
+
+ replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+
+ verify();
+ }
+
+ public void checkDisabled(Object attributeValue, boolean expectedValue) throws
Exception {
+ componentAttributes.put("disabled", attributeValue);
+
+ UIComponent component = createMockComponent();
+ replay();
+ assertTrue(expectedValue == RenderKitUtils.isDisabled(component));
+ verify();
+ }
+
+ @Test
+ public void testIsDisabled() throws Exception {
+ checkDisabled(Boolean.TRUE, true);
+ }
+
+ @Test
+ public void testIsDisabledString() throws Exception {
+ checkDisabled("true", true);
+ }
+
+ @Test
+ public void testIsNonDisabled() throws Exception {
+ checkDisabled(Boolean.FALSE, false);
+ }
+
+ @Test
+ public void testIsNonDisabledString() throws Exception {
+ checkDisabled("false", false);
+ }
+
+ @Test
+ public void testIsNonDisabledNull() throws Exception {
+ checkDisabled(null, false);
+ }
+
+ private UIComponent setupTestDecodeBehaviors(String behaviorSourceId, String
behaviorEventName) throws Exception {
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
+
+ Map<String, String> requestParameterMap = new HashMap<String,
String>();
+ requestParameterMap.put(RenderKitUtils.BEHAVIOR_SOURCE_ID, behaviorSourceId);
+ requestParameterMap.put(RenderKitUtils.BEHAVIOR_EVENT_NAME, behaviorEventName);
+
expect(externalContext.getRequestParameterMap()).andStubReturn(requestParameterMap);
+
+ ClientBehavior actionBehavior = createClientBehavior("action1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ ClientBehavior actionBehavior1 = createClientBehavior("action2",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ behaviorsMap.put("action", Arrays.asList(actionBehavior,
actionBehavior1));
+
+ ClientBehavior blurBehavior = createClientBehavior("blur1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ behaviorsMap.put("blur", Arrays.asList(blurBehavior));
+
+ return component;
+ }
+
+ @Test
+ public void testDecodeActionBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "action");
+
+ List<ClientBehavior> behaviors = behaviorsMap.get("action");
+ for (ClientBehavior clientBehavior : behaviors) {
+ clientBehavior.decode(same(facesContext), same(component));
+ expectLastCall();
+ }
+
+ replay();
+
+ RenderKitUtils.decodeBehaviors(facesContext, component);
+
+ verify();
+ }
+
+ @Test
+ public void testDecodeBlurBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "blur");
+
+ List<ClientBehavior> behaviors = behaviorsMap.get("blur");
+ for (ClientBehavior clientBehavior : behaviors) {
+ clientBehavior.decode(same(facesContext), same(component));
+ expectLastCall();
+ }
+
+ replay();
+
+ RenderKitUtils.decodeBehaviors(facesContext, component);
+
+ verify();
+ }
+
+ @Test
+ public void testDecodeNonMatchingClientId() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors("wrongId",
"action");
+
+ //nothing should be called - clientId is not matched
+
+ replay();
+
+ RenderKitUtils.decodeBehaviors(facesContext, component);
+
+ verify();
+ }
+
+ @Test
+ public void testDecodeNoSubmittedBehavior() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, null);
+
+ //nothing should be called - no behavior event information was submitted
+
+ replay();
+
+ RenderKitUtils.decodeBehaviors(facesContext, component);
+
+ verify();
+ }
+
+ @Test
+ public void testDecodeContextMenuBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID,
"contextmenu");
+
+ //nothing should be called - no context menu behaviors were created
+
+ replay();
+
+ RenderKitUtils.decodeBehaviors(facesContext, component);
+
+ verify();
+ }
}
\ No newline at end of file
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2010-02-21
23:15:30 UTC (rev 16478)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2010-02-21
23:19:48 UTC (rev 16479)
@@ -167,7 +167,7 @@
}
} else {
renderedAreas.add(component.getClientId(context));
- renderChild(context, component);
+ component.encodeAll(context);
}
}
}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-02-21
23:15:30 UTC (rev 16478)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-02-21
23:19:48 UTC (rev 16479)
@@ -21,24 +21,21 @@
package org.ajax4jsf.renderkit;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
import org.ajax4jsf.Messages;
import org.ajax4jsf.resource.InternetResource;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.renderkit.RenderKitUtils;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
import org.slf4j.Logger;
-import javax.faces.component.UIComponent;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
/**
* Base Renderer for all chameleon Skin's and components.
* At most, make all common procedures and realise concrete work in "template"
methods.
@@ -82,42 +79,11 @@
// TODO - create set od common decoders ( UIInput, ActionSource etc. ) for
process decoding.
if (component.isRendered()) {
- decodeBehaviors(context, component);
+ RenderKitUtils.decodeBehaviors(context, component);
doDecode(context, component);
}
}
- protected void decodeBehaviors(FacesContext context, UIComponent component) {
- if (!(component instanceof ClientBehaviorHolder)) {
- return;
- }
-
- ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
- Map<String, List<ClientBehavior>> behaviors =
holder.getClientBehaviors();
-
- if (behaviors.isEmpty()) {
- return;
- }
-
- ExternalContext external = context.getExternalContext();
- Map<String, String> params = external.getRequestParameterMap();
- String behaviorEvent = params.get("javax.faces.behavior.event");
-
- if (behaviorEvent == null) {
- return;
- }
-
- List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
- String behaviorSource = params.get("javax.faces.source");
- String clientId = component.getClientId();
-
- if ((null != behaviorSource) && behaviorSource.equals(clientId)) {
- for (ClientBehavior behavior : behaviorsForEvent) {
- behavior.decode(context, component);
- }
- }
- }
-
protected void preDecode(FacesContext context, UIComponent component) {
}
@@ -306,34 +272,13 @@
* @throws IOException
*/
public void renderChildren(FacesContext facesContext, UIComponent component) throws
IOException {
- for (UIComponent child : component.getChildren()) {
- renderChild(facesContext, child);
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ child.encodeAll(facesContext);
+ }
}
}
- /**
- * Render one component and it childrens
- *
- * @param facesContext
- * @param child
- * @throws IOException
- */
- public void renderChild(FacesContext facesContext, UIComponent child) throws
IOException {
- if (!child.isRendered()) {
- return;
- }
-
- child.encodeBegin(facesContext);
-
- if (child.getRendersChildren()) {
- child.encodeChildren(facesContext);
- } else {
- renderChildren(facesContext, child);
- }
-
- child.encodeEnd(facesContext);
- }
-
// TODO method stub - replace with JSF 2.0 annotations
public InternetResource getResource(String name) {
return null;
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2010-02-21
23:15:30 UTC (rev 16478)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2010-02-21
23:19:48 UTC (rev 16479)
@@ -67,7 +67,7 @@
if (children) {
this.renderChildren(context, component);
} else {
- this.renderChild(context, component);
+ component.encodeAll(context);
}
saxResponseWriter.endElement("root");