Author: alexsmirnov
Date: 2011-02-18 18:13:24 -0500 (Fri, 18 Feb 2011)
New Revision: 21787
Added:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/generate/java/TestAttributesThatAreSet.java
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates/_attribute_accessors.ftl
trunk/cdk/generator/src/main/resources/META-INF/templates/_attributes.ftl
Log:
RESOLVED - issue RF-8362: CDK Pass-through attributes rendering: component-related code
https://issues.jboss.org/browse/RF-8362
RESOLVED - issue RF-10004: CDK: isEmpty method is generated incorrectly
https://issues.jboss.org/browse/RF-10004
RESOLVED - issue RF-10293: richfaces-showcase: message: not updated via ajax but h:message
+ outputPanel does.
https://issues.jboss.org/browse/RF-10293
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates/_attribute_accessors.ftl
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates/_attribute_accessors.ftl 2011-02-18
20:26:27 UTC (rev 21786)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/_attribute_accessors.ftl 2011-02-18
23:13:24 UTC (rev 21787)
@@ -20,5 +20,8 @@
<#if ! attribute.readOnly >
public void ${attribute.setterName}(${attribute.typeName} ${propertyKey}) {
getStateHelper().put(Properties.${propertyKey}, ${propertyKey});
+ <#if attribute.passThrough >
+ handleAttribute("${attribute.name}",${propertyKey});
+ </#if>
}
</#if>
\ No newline at end of file
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/_attributes.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/_attributes.ftl 2011-02-18
20:26:27 UTC (rev 21786)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/_attributes.ftl 2011-02-18
23:13:24 UTC (rev 21787)
@@ -15,7 +15,29 @@
return ((this.toString != null) ? this.toString : super.toString());
}</#if>
}
-
+ <#assign passThroughCount=0>
<#list generatedAttributes as attribute>
+ <#if attribute.passThrough >
+ <#assign passThroughCount=passThroughCount+1/>
+ </#if>
<#include "_attribute_accessors.ftl">
</#list>
+ <#if passThroughCount gt 0 >
+ private static final String ATTRIBUTES_THAT_ARE_SET_KEY =
"javax.faces.component.UIComponentBase.attributesThatAreSet";
+
+ private void handleAttribute(String name, Object value) {
+ List<String> setAttributes = (List<String>)
this.getAttributes().get(ATTRIBUTES_THAT_ARE_SET_KEY);
+ if (setAttributes == null) {
+ setAttributes = new ArrayList<String>(${passThroughCount});
+ this.getAttributes().put(ATTRIBUTES_THAT_ARE_SET_KEY, setAttributes);
+ }
+ if (value == null) {
+ ValueExpression ve = getValueExpression(name);
+ if (ve == null) {
+ setAttributes.remove(name);
+ }
+ } else if (!setAttributes.contains(name)) {
+ setAttributes.add(name);
+ }
+ }
+ </#if>
\ No newline at end of file
Added:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/generate/java/TestAttributesThatAreSet.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/generate/java/TestAttributesThatAreSet.java
(rev 0)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/generate/java/TestAttributesThatAreSet.java 2011-02-18
23:13:24 UTC (rev 21787)
@@ -0,0 +1,187 @@
+package org.richfaces.cdk.generate.java;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.html.HtmlCommandLink;
+
+import org.junit.Test;
+
+/**
+ * <p class="changed_added_4_0">
+ * Test functionality of 'attributesThatAreSet' collection
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestAttributesThatAreSet {
+
+ private static final String RENDERED = "rendered";
+
+ private static final String ID = "id";
+
+ private static final String ATTRIBUTES_THAT_ARE_SET_KEY =
UIComponentBase.class.getName() + ".attributesThatAreSet";
+
+ private static final @SuppressWarnings("serial")
+ ValueExpression DUMMY_EXPRESSION = new ValueExpression() {
+
+ @Override
+ public boolean isLiteralText() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getExpressionString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Object getValue(ELContext context) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<?> getExpectedType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+
+ @Test
+ public void testId() throws Exception {
+ UIComponentBase component = createComponentBase();
+ assertAttributeNotSet(component, ID);
+ component.setId("foo");
+ assertAttributeNotSet(component, ID);
+ }
+
+ @Test
+ public void testIdByAttributes() throws Exception {
+ UIComponentBase component = createComponentBase();
+ assertAttributeNotSet(component, ID);
+ component.getAttributes().put(ID,"foo");
+ assertAttributeNotSet(component, ID);
+ }
+
+ @Test
+ public void testRenderedSet() throws Exception {
+ UIComponentBase component = createComponentBase();
+ assertAttributeNotSet(component, RENDERED);
+ component.setRendered(true);
+ assertAttributeNotSet(component, RENDERED);
+ }
+
+ @Test
+ public void testRenderedAttribute() throws Exception {
+ UIComponentBase component = createComponentBase();
+ assertAttributeNotSet(component, RENDERED);
+ component.getAttributes().put(RENDERED, true);
+ assertAttributeNotSet(component, RENDERED);
+ }
+
+ @Test
+ public void testRenderedByEl() throws Exception {
+ UIComponentBase component = createComponentBase();
+ assertAttributeNotSet(component, RENDERED);
+ component.setValueExpression(RENDERED, DUMMY_EXPRESSION);
+ assertAttributeSet(component, RENDERED);
+ }
+
+ @Test
+ public void testInputMessage() throws Exception {
+ UIInput input = new UIInput();
+ input.setConverterMessage("foo");
+ assertAttributeNotSet(input, "converterMessage");
+ }
+
+ @Test
+ public void testCustomProperty() throws Exception {
+ UIInput input = new UIInput();
+ input.getAttributes().put("foobar", RENDERED);
+ assertAttributeSet(input, "foobar");
+ }
+
+ @Test
+ public void testHtmlAttribute() throws Exception {
+ HtmlCommandLink link = new HtmlCommandLink();
+ link.setDir("lefttoright");
+ assertAttributeSet(link, "dir");
+ }
+
+ private UIComponentBase createComponentBase() {
+ UIComponentBase component = new UIComponentBase() {
+
+ @Override
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ };
+ return component;
+ }
+
+ private void assertAttributeSet(UIComponent component, String attribute) {
+ List<String> list = getAttributesList(component);
+ assertTrue(list.contains(attribute));
+ }
+
+ private void assertAttributeNotSet(UIComponent component, String attribute) {
+ List<String> list = getAttributesList(component);
+ assertFalse(list.contains(attribute));
+ }
+
+ private List<String> getAttributesList(UIComponent component) {
+ Object attributesList =
component.getAttributes().get(ATTRIBUTES_THAT_ARE_SET_KEY);
+ if (null != attributesList) {
+ assertTrue(attributesList instanceof List<?>);
+ List<String> list = (List<String>) attributesList;
+ return list;
+
+ } else {
+ return Collections.emptyList();
+ }
+ }
+}
Property changes on:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/generate/java/TestAttributesThatAreSet.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain