[
https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479644
]
Zdenek Sochor commented on TOMAHAWK-928:
----------------------------------------
I submitted my suggestion too soon.
By checking source of Java API Class methods used for introspection i realized
that using getMethod()
is NOT the way to do the task.
Proper way is to check both getter forms in each class in hiearchy.
This handles both issues (inheritance and performance).
I have the patch ready, but i can't attach it here (no write permission)
Code in try block (line 112):
String attributeName = attributeNames[cnt];
if (attributeName.equals("id") ||
attributeName.equals("widgetId")) {
String calculatedId =
DojoUtils.calculateWidgetId(facesContext, component);
returnMap.put("id", calculatedId);
} else {
String attributeCasedName = attributeName.substring(0,
1).toUpperCase() + attributeName.substring(1);
String getForm = "get" + attributeCasedName; // to prevent
multiple creating in finding
String isForm = "is" + attributeCasedName; // to prevent
multiple creating in finding
Method m = null;
// finding getter in hiearchy: try current class for "get"
and "is" form, if NOT found, try superclass
// doesn't use getMethod() to avoid walking whole hiearchy
for wrong form in case of "is"
// and getMethod() uses getSuperClass() anyway, so no
performance hit this way + ability to invoke protected methods
while ((componentClass != null) && (m == null)) {
m = componentClass.getDeclaredMethod(getForm, null);
if (m == null) {
// try alternative method name for dealing with
Booleans
m = componentClass.getDeclaredMethod(isForm,
null);
}
if (m == null) {
// load superclass
componentClass = componentClass.getSuperclass(); //
null in case of componentClass == Object
}
}
if (m != null) {
Object execRetval = m.invoke(component, null);
if (execRetval != null)
returnMap.put(attributeName, execRetval);
}
}
Zdenek
> DojoUtils.getAttributeMap fails for subclassed Dojo Components
> --------------------------------------------------------------
>
> Key: TOMAHAWK-928
> URL: https://issues.apache.org/jira/browse/TOMAHAWK-928
> Project: MyFaces Tomahawk
> Issue Type: Bug
> Affects Versions: 1.1.5-SNAPSHOT
> Reporter: Stefan Schuster
> Assigned To: Werner Punz
> Fix For: 1.1.5-SNAPSHOT
>
> Attachments: DojoUtils.patch, DojoUtilsV2.patch
>
>
> When using DojoUtils.renderWidgetInitializationCode() with a String Array as
> arguments parameter introspection get's used to find the getters for the
> given Strings. When subclassing a dojo based widget this mechanisms fails
> with a NoSuchMethodException.
> The introspection happens in DojoUtils.getAttributeMap() and uses
> Class.getDeclaredMethod() instead of Class.getMethod() which won't find the
> inherited getters. Changing this makes the mechanism working with subclassed
> components too.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.