Uploaded image for project: 'RichFaces'
  1. RichFaces
  2. RF-13776

a4j:ajax problem with hierarchical component IDs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 4.3.7
    • Fix Version/s: 4.5.16
    • Component/s: component-a4j-core
    • Labels:
      None
    • Environment:

      RichFaces 4.3.7
      Mojarra 2.1.29
      Java 7 Update 67 (x64)
      Tomcat 7.0.52 (x64)

      Description

      First of all: this is a bug report related to RF-12616.

      The actionListener of an a4j:ajax-enhanced component is not invoked on the server side. In a nutshell the problem is due to the request parameter "javax.faces.source" not matching the id of the component for which the AjaxBehaviorEvent is bound.

      The problem occurs when you assign hierarchical component ids in your xhtml.

      Here is a condensed snippet xhtml illustrating the problem:

      Snippet

      <rich:treeNode id="treeNode">
         <h:selectBooleanCheckbox id="treeNodeSelectBox">
            <a4j:ajax event="click" execute="@this" listener="#{someManagedBean.onCheckboxClick}" />
         </h:selectBooleanCheckbox>
      </rich:treeNode>
      

      As you can see, the id of the selectBooleanCheckbox begins with the id of the treeNode.

      The RichFaces JavaScript handler introduced a function to obviously evaluate the correct component id for the event (which is then passed as request parameter 'javax.faces.source' in the AJAX request).

      RichFaces JS-Snippet

          richfaces.ajax = function(source, event, options) {
              var options = options || {};
              
              var sourceId = getSourceId(source, options);
              var sourceElement = getSourceElement(source);
              
              // event source re-targeting finds a RichFaces component root
              // to setup javax.faces.source correctly - RF-12616)
              if (sourceElement) {
                  source = searchForComponentRootOrReturn(sourceElement);
              }
      		
      		...
       
          /*
           * Returns RichFaces component root for given element in the list of ancestors of sourceElement.
           * Otherwise returns sourceElement if RichFaces component root can't be located.
           */
          var searchForComponentRootOrReturn = function(sourceElement) {
              if (sourceElement.id && !richfaces.$(sourceElement)) {
                  var parentElement = false;
                  jQuery(sourceElement).parents().each(function() {
                      if (this.id && sourceElement.id.indexOf(this.id) == 0) { // otherwise parent element is definitely not JSF component
                          var suffix = sourceElement.id.substring(this.id.length); // extract suffix
                          if (suffix.match(/^[a-zA-Z]*$/) && richfaces.$(this)) {
                              parentElement = this;
                              return false;
                          }
                      }
                  });
                  if (parentElement !== false) {
                      return parentElement;
                  }
              }
              return sourceElement;
          };
      

      The problem is within the function "searchForComponentRootOrReturn" which in this special case of id-hierarchy evaluates to the wrong element. The correct element to be returned here would be the "sourceElement" (selectBooleanCheckbox with the id "treeNodeSelectBox" in the example above), but the code evaluates to a "parentElement" (treeNode in the example above) due to its id "treeNode" being a prefix of the component which fired the event.

      It took me a whole day to figure that one out, since there is no useful output neither in a4j:log nor in server side logging in a case where the parameter "javax.faces.source" does not match the component id. In fact the AJAX request is executed just fine, only the event is never queued...
      (See Mojarra HtmlBasicRenderer => decodeBehaviors and its check method isBehaviorSource)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                michpetrov Michal Petrov
                Reporter:
                michaelb80 Michael B
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1 hour
                  1h
                  Remaining:
                  Remaining Estimate - 1 hour
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified