You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Stefan Schuster (JIRA)" <de...@myfaces.apache.org> on 2007/03/09 14:09:24 UTC

[jira] Created: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

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
             Fix For: 1.1.5-SNAPSHOT
         Attachments: DojoUtils.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.


[jira] Updated: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Werner Punz (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Werner Punz updated TOMAHAWK-928:
---------------------------------

    Resolution: Fixed
        Status: Resolved  (was: Patch Available)

Ok it looks good, all bugs I encountered did not seem to be caused by
the deeper inheritance for the attribute map,
anyway, someone introduced a bunch of bugs in the tomahawk rendering utils which seem to break the dialog, but that also happens on the old code.
This has nothing to do with this issue here,


> 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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Stefan Schuster (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479623 ] 

Stefan Schuster commented on TOMAHAWK-928:
------------------------------------------

Well that sounds reasonable.
I'm not sure about the "protected" argument, but the performance aspect convinced me. Therefore I implemented your suggestion and added an enhanced patch. So now it works like before, but inherited members will be found too in the 3rd and 4th attempt.

Stefan

> 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.


[jira] Updated: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Stefan Schuster (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Schuster updated TOMAHAWK-928:
-------------------------------------

    Status: Patch Available  (was: Open)

> 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
>             Fix For: 1.1.5-SNAPSHOT
>
>         Attachments: DojoUtils.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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Zdenek Sochor (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479602 ] 

Zdenek Sochor commented on TOMAHAWK-928:
----------------------------------------

Hi,
 the patch won't solve other issues:

a) getMethod introspection call returns only public methods (getDeclaredMethod() returns protected methods too)

b) if getter is in "is" form, getMethod() will walk through all superclasses 1st for "get" form finding nothing, then trying the same approach for "is" form and this could be a huge performance hit in deep class hiearchy.

so little more work on patch will be needed, it would require little insight of more common uses of components.

I suggest trying finding methods by calling getDeclaredMethod() for both forms 1st and then if no method found try to use getMethod() calls.

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
>
>
> 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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Werner Punz (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479834 ] 

Werner Punz commented on TOMAHAWK-928:
--------------------------------------

Yes this indeed looks good, I am applying it as we speak,
Thanks a lot Zdenek, I learned a lot about those issues here :-)


> 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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Stefan Schuster (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479712 ] 

Stefan Schuster commented on TOMAHAWK-928:
------------------------------------------

In my opinion this looks good and finally solves the performance issues while covering both, "is" and "get" getters.

Werner?

> 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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Zdenek Sochor (JIRA)" <de...@myfaces.apache.org>.
    [ 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.


[jira] Commented: (TOMAHAWK-928) DojoUtils.getAttributeMap fails for subclassed Dojo Components

Posted by "Werner Punz (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/TOMAHAWK-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12479581 ] 

Werner Punz commented on TOMAHAWK-928:
--------------------------------------

thanks this is indeed a bug, I will commit the fix tonight, thanks for the fix and the patch, all contributions are welcome

> 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
>
>
> 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.