Author: nbelaevski
Date: 2010-10-24 15:54:39 -0400 (Sun, 24 Oct 2010)
New Revision: 19659
Modified:
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
Log:
https://jira.jboss.org/browse/RF-8957
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-10-24
19:12:42 UTC (rev 19658)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-10-24
19:54:39 UTC (rev 19659)
@@ -304,14 +304,12 @@
return result.toString();
}
- public static boolean shouldRenderAttribute(Object attributeValue) {
+ private static boolean isAttributeSet(Object attributeValue) {
//TODO - consider required attributes with "" value (like
'alt')
if (attributeValue == null) {
return false;
} else if (attributeValue instanceof String) {
return ((String) attributeValue).length() > 0;
- } else if (attributeValue instanceof Boolean &&
Boolean.FALSE.equals(attributeValue)) {
- return false;
} else if (attributeValue instanceof Integer && (Integer) attributeValue
== Integer.MIN_VALUE) {
return false;
} else if (attributeValue instanceof Double && (Double) attributeValue ==
Double.MIN_VALUE) {
@@ -330,7 +328,20 @@
return attributeValue.toString().length() > 0;
}
+
+ public static boolean shouldRenderAttribute(Object attributeValue) {
+ //TODO - consider required attributes with "" value (like
'alt')
+ if (!isAttributeSet(attributeValue)) {
+ return false;
+ }
+
+ if (attributeValue instanceof Boolean &&
Boolean.FALSE.equals(attributeValue)) {
+ return false;
+ }
+ return attributeValue.toString().length() > 0;
+ }
+
public static String prefixAttributeName(String attributeName, boolean isXhtmlMode)
{
if (isXhtmlMode) {
if (Arrays.binarySearch(XHTML_ATTRIBUTE_NAMES, attributeName) >= 0) {
@@ -599,7 +610,7 @@
ScriptHashVariableWrapper wrapperOrDefault = wrapper != null ? wrapper :
ScriptHashVariableWrapper.noop;
- if (!isEmpty(value) && shouldRenderAttribute(value)) {
+ if (!isEmpty(value) && isAttributeSet(value)) {
if (defaultValue != null) {
if (!String.valueOf(defaultValue).equals(value.toString())) {
hash.put(name, wrapperOrDefault.wrap(value));
Modified:
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
===================================================================
---
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-10-24
19:12:42 UTC (rev 19658)
+++
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-10-24
19:54:39 UTC (rev 19659)
@@ -39,6 +39,7 @@
import java.util.TreeSet;
import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.junit.Test;
import org.richfaces.renderkit.RenderKitUtils.ScriptHashVariableWrapper;
@@ -163,6 +164,7 @@
assertEquals("1,2,null,3", toScriptArgs(1, 2, null, 3));
}
+ @Test
public void testScriptHashVariableWrapper() throws Exception {
assertEquals("abc",
ScriptHashVariableWrapper.noop.wrap("abc"));
@@ -174,9 +176,10 @@
assertEquals("function(event){abc}",
dehydrate(handlerFunction.toScript()));
Object arrayObject = ScriptHashVariableWrapper.asArray.wrap("header,
footer");
- assertEquals("[\"header\",\"footer\"]",
arrayObject.toString().replaceAll("\\s", ""));
+ assertEquals("[\"header\",\"footer\"]",
dehydrate(ScriptUtils.toScript(arrayObject)));
}
+ @Test
public void testAddToScriptHash() throws Exception {
Map<String, Object> hash = new HashMap<String, Object>();
@@ -237,11 +240,12 @@
assertTrue(hash.get("onclick1") instanceof JSFunctionDefinition);
}
-
+ @Test
public void testAsArray() {
assertNull(RenderKitUtils.asArray(null));
}
+ @Test
public void testAsArray1() {
String[] strings = new String[] {"a", "b"};
String[] array = RenderKitUtils.asArray(strings);
@@ -249,6 +253,7 @@
assertSame(strings, array);
}
+ @Test
public void testAsArray2() {
Object[] objects = new Object[] {Integer.valueOf(12), null, Integer.valueOf(22),
Integer.valueOf(42)};
String[] array = RenderKitUtils.asArray(objects);
@@ -257,6 +262,7 @@
assertTrue(Arrays.equals(etalon, array));
}
+ @Test
public void testAsArray3() {
ArrayList<Integer> list = new ArrayList<Integer>();
@@ -271,6 +277,7 @@
assertTrue(Arrays.equals(etalon, array));
}
+ @Test
public void testAsArray31() {
Set<Integer> set = new TreeSet<Integer>();
@@ -284,6 +291,7 @@
assertTrue(Arrays.equals(etalon, array));
}
+ @Test
public void testAsArray4() {
String string = " a , \t\n b \n , c ";
String[] strings = RenderKitUtils.asArray(string);