[richfaces-issues] [JBoss JIRA] (RF-13780) Random JavaScript error due to missing attribute 'richfaces.RICH_CONTAINER'

Michael B (JIRA) issues at jboss.org
Mon Aug 18 08:17:31 EDT 2014


    [ https://issues.jboss.org/browse/RF-13780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12993415#comment-12993415 ] 

Michael B edited comment on RF-13780 at 8/18/14 8:16 AM:
---------------------------------------------------------

[~bleathem] it seems you are right - it looks like a problem after an AJAX update. - I'll get to that in a moment...

First, thanks for the link to the debug guide, - besides ui:debug, we're already using what's described there.

-Trying with RF 4.5.0 Alpha 3 unfortunately is not an option at this point in time, because we are already far behind our project schedule due to several problems with JSF(Mojarra) and RF. Also migrating a really big application to RF 4.5 (even if its just for testing) takes time we don't have right now and by the looks of it is no trivial matter at least if I consider the- migration guide [https://github.com/richfaces/richfaces/wiki/Migration-from-RichFaces-4-to-RichFaces-4.5]. 
-Reproducing the problem with a small test application (as we usually do it) failed on the first try. But maybe we can afford a little more time to trying to reproduce the problem in that environment and then migrating the test application to RF 4.5 ...-

But back to the original problem - we tried to debug a little further with the big application and what we've found so far seems to confirm that the problem lies in an AJAX update:
# The "toggleType" of the tree is set to "ajax", because there's some data loading and calculations to be done when toggling the tree
# Clicking on a tree expander icon fires the ajax request
# The partial response is evaluated and updates several components
# One of the components in the partial response update is {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode{code} BTW: "limitRender" is not respected if set on the tree! (which causes other problems - maybe also this one?!) - so that's why there are updates to other components like messages etc. as well.
# The partial response is handled by this function: {code}    var ajaxOnComplete = function (data) {
        var type = data.type;
        var responseXML = data.responseXML;

        if (data.type == 'event' && data.status == 'complete' && responseXML) {
            var partialResponse = jQuery(responseXML).children("partial-response");
            if (partialResponse && partialResponse.length) {
                var elements = partialResponse.children('changes').children('update, delete');
                jQuery.each(elements, function () {
                    richfaces.cleanDom(jQuery(this).attr('id'));
                });
            }
        }
    };{code}
# For every updated or deleted component "richfaces.cleanDom" is invoked. "cleanDom" calls "cleanComponent" which in the end calls "detach" (already shown in a previous post above)
# This leads to the tree node {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode.rf-tr-nd.rf-tr-nd-colps{code} losing its "component" attachment.
# After cleanig the DOM, the components are attached to the elements. I can see - amongst others - a call to "attachToDom" for the ID {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode.rf-tr-nd.rf-tr-nd-exp{code}
# After processing the partial response the toggleEvent is fired as already described above. 
# The function "richfaces.$" doesn't find the tree node component anymore, because it has been detached and re-attached to the expanded node just a moment ago


was (Author: michaelb80):
[~bleathem] it seems you are right - it looks like a problem after an AJAX update. - I'll get to that in a moment...

First, thanks for the link to the debug guide, - besides ui:debug, we're already using what's described there.

Trying with RF 4.5.0 Alpha 3 unfortunately is not an option at this point in time, because we are already far behind our project schedule due to several problems with JSF(Mojarra) and RF. Also migrating a really big application to RF 4.5 (even if its just for testing) takes time we don't have right now and by the looks of it is no trivial matter - at least if I consider the migration guide [https://github.com/richfaces/richfaces/wiki/Migration-from-RichFaces-4-to-RichFaces-4.5]. 
Reproducing the problem with a small test application (as we usually do it) failed on the first try. But maybe we can afford a little more time to trying to reproduce the problem in that environment and then migrating the test application to RF 4.5 ...

But back to the original problem - we tried to debug a little further with the big application and what we've found so far seems to confirm that the problem lies in an AJAX update:
# The "toggleType" of the tree is set to "ajax", because there's some data loading and calculations to be done when toggling the tree
# Clicking on a tree expander icon fires the ajax request
# The partial response is evaluated and updates several components
# One of the components in the partial response update is {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode{code} BTW: "limitRender" is not respected if set on the tree! (which causes other problems - maybe also this one?!) - so that's why there are updates to other components like messages etc. as well.
# The partial response is handled by this function: {code}    var ajaxOnComplete = function (data) {
        var type = data.type;
        var responseXML = data.responseXML;

        if (data.type == 'event' && data.status == 'complete' && responseXML) {
            var partialResponse = jQuery(responseXML).children("partial-response");
            if (partialResponse && partialResponse.length) {
                var elements = partialResponse.children('changes').children('update, delete');
                jQuery.each(elements, function () {
                    richfaces.cleanDom(jQuery(this).attr('id'));
                });
            }
        }
    };{code}
# For every updated or deleted component "richfaces.cleanDom" is invoked. "cleanDom" calls "cleanComponent" which in the end calls "detach" (already shown in a previous post above)
# This leads to the tree node {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode.rf-tr-nd.rf-tr-nd-colps{code} losing its "component" attachment.
# After cleanig the DOM, the components are attached to the elements. I can see - amongst others - a call to "attachToDom" for the ID {code}<...>:tree:treeModelAdapter.0.treeModelAdapter.2:treeNode.rf-tr-nd.rf-tr-nd-exp{code}
# After processing the partial response the toggleEvent is fired as already described above. 
# The function "richfaces.$" doesn't find the tree node component anymore, because it has been detached and re-attached to the expanded node just a moment ago

> Random JavaScript error due to missing attribute 'richfaces.RICH_CONTAINER'
> ---------------------------------------------------------------------------
>
>                 Key: RF-13780
>                 URL: https://issues.jboss.org/browse/RF-13780
>             Project: RichFaces
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: component, component-tree
>    Affects Versions: 4.3.7
>         Environment: RichFaces 4.3.7
> Mojarra 2.1.29
> Java 7 Update 67 (x64)
> Tomcat 7.0.52 (x64) 
> Firefox 31
>            Reporter: Michael B
>
> First of all: this is a bug report which may be related to RF-13776, since it also originates in the same spot of the JavaScript library of RichFaces.
> Preface:
> The problem is difficult to reproduce systematically, since it only seems to occur in one of n cases of loading one and the same complex xhtml (with exactly the same data from the backing bean).
> The problem is described based on the rich:tree component when clicking on the expand icon of a treeNode which fires a "ToggleEvent".
> Occasionally there is a JavaScript error in the last line of 
> {code}
>     richfaces.ui.TreeNode.emitToggleEvent = function(nodeId) {
>         var node = document.getElementById(nodeId);
>         if (!node) {
>             return;
>         }
>         richfaces.$(node).__fireToggleEvent();
>     };
> {code}
> When the problem occurs, the expression {code}richfaces.$(node){code} evaluates to 'undefined'. 
> Debugging into the function when the problem occurs:
> {code:title=richfaces.$|borderStyle=solid}
> richfaces.$ = function(source) {
>    var element = richfaces.getDomElement( source );
>    if(element)
>    {
>       return( element[richfaces.RICH_CONTAINER] || {} )["component"]
>    }
> };
> {code}
> While the element is correctly evaluated to the treeNode/treeNodeToggle-source, the expression {code}element[richfaces.RICH_CONTAINER]{code} evaluates to 'undefined'.
> Reloading the page one or more times produces correct results, where the attribute is set.
> To be able to provide a reproducable example of the problem, please provide some information under which circumstances the property may not be set correctly for some components. Please also give us a hint, where to debug into the RF JavaScript code to find the spot where this property is set.
> Although the problem doesn't occur all the time, it happens quite often with the effect of breaking the entire application. So for future versions I would suggest a check if {code}richfaces.$(xyz){code} evalutes to a valid result, before invoking any operations on the result and maybe write a message to the a4j:log in cases where a valid result is expected but not returned.



--
This message was sent by Atlassian JIRA
(v6.2.6#6264)


More information about the richfaces-issues mailing list