Author: mvitenkov
Date: 2008-10-22 07:48:13 -0400 (Wed, 22 Oct 2008)
New Revision: 10862
Modified:
trunk/test-applications/jsp/src/main/java/util/componentInfo/ComponentInfo.java
Log:
Correction with util.TLDParser
Modified: trunk/test-applications/jsp/src/main/java/util/componentInfo/ComponentInfo.java
===================================================================
---
trunk/test-applications/jsp/src/main/java/util/componentInfo/ComponentInfo.java 2008-10-22
11:47:37 UTC (rev 10861)
+++
trunk/test-applications/jsp/src/main/java/util/componentInfo/ComponentInfo.java 2008-10-22
11:48:13 UTC (rev 10862)
@@ -6,17 +6,16 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
+import org.richfaces.component.UICalendar;
+
+import util.parser.TLDParser;
+
public class ComponentInfo {
private static volatile ComponentInfo INSTANCE;
private ComponentAttribute componentAttribute = new ComponentAttribute();
@@ -69,23 +68,34 @@
public void addField(Object component) {
if (component == null)
return;
- this.component = component;
+ this.component = component;
- //if(ve.isLiteralText()) {ve.getExpressionString()} {ve.getValue(). }
-
componentAttribute.cleanAll();
String str = null;
Field[] fields = component.getClass().getDeclaredFields();
+
+ String richName = null;
+ if(component.getClass().getName().startsWith("org.richfaces.component.html.Html")){
+ richName =
component.getClass().getName().substring("org.richfaces.component.html.Html".length()).toLowerCase();
+ } else {
+ try {
+ throw new Exception("Unknown class for component!!!");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ TLDParser parser = new TLDParser(richName);
+ ArrayList<String> allAttributes = parser.getAllAttributes();
+
AccessibleObject.setAccessible(fields, true);
for (Field field : fields) {
- if (!Modifier.isStatic(field.getModifiers())) {
- str = field.getName().substring(1);
+ str = field.getName().substring(1);
+ if (!Modifier.isStatic(field.getModifiers()) && (allAttributes.contains(str)))
{
if (str.startsWith("on")) {
componentAttribute.putEvent(str,
"");
} else if (str.indexOf("tyle") != -1 || str.indexOf("lass") !=
-1) {
- try {
- //Object obj = field.get(component);
+ try {
UIComponentBase comp = (UIComponentBase) component;
ValueExpression ve = comp.getValueExpression(str);
if(ve != null){
@@ -96,15 +106,14 @@
}
} else componentAttribute.putStyle(str, "null");
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
+ } catch (IllegalArgumentException e) {
e.printStackTrace();
}
} else {
try {
- Class cl = field.getType();
+ Class cl = field.getType();
if(cl.isPrimitive() || cl.getName().equals("java.lang.String")){
UIComponentBase comp = (UIComponentBase) component;
ValueExpression ve = comp.getValueExpression(str);
@@ -115,8 +124,6 @@
componentAttribute.putAttribute(str,
ve.getValue(FacesContext.getCurrentInstance().getELContext()).toString());
}
}else componentAttribute.putAttribute(str, "null");
-// Object obj = field.get(component);
-// componentAttribute.putAttribute(str, obj == null ? "null" :
obj.toString());
} else componentAttribute.putAttribute(str, "---");
} catch (IllegalArgumentException e) {
e.printStackTrace();
@@ -127,7 +134,7 @@
}
- public static String toString(Object obj) {
+ public static String toString(Object obj) {
Class cl = obj.getClass();
String r = cl.getName() + "[";
Class sc = cl.getSuperclass();
Show replies by date