[
https://issues.jboss.org/browse/RF-13776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12992949#comment-12992949
]
Michael B edited comment on RF-13776 at 8/14/14 10:33 AM:
----------------------------------------------------------
[~bleathem] meanwhile I've tried the 2 things you asked for - although the ID
for the second test has to be a little different.
bq. 1. Replace the JSF <h:selectBooleanCheckbox> with a RichFaces component?
I've replaced the selectBooleanCheckbox with a rich:select and an a4j:ajax
event="selectitem". In this case the event is fired correctly - even if the ids
are similar. The reason for that is, that the select has the
{code}element[richfaces.RICH_CONTAINER]{code} and so a search for a parent is
not required.
bq. 2. Check what
RichFaces.$(document.getElementById("form:treeNode:treeNodeSelectBox"))
evaluates to?
Since a treeNode cannot be used without a valid tree around, a valid id will be
"form:tree:treeModelAdapter.0:treeNodeSelectBox".
A test of
{code}document.getElementById("form:tree:treeModelAdapter.0:treeNodeSelectBox"){code}
evaluates to the checkbox, while a test of {code}RichFaces.$(
document.getElementById("form:tree:treeModelAdapter.0:treeNodeSelectBox")
){code} evaluates to 'undefined', since
{code}element[richfaces.RICH_CONTAINER]{code} is not defined for the
selectBooleanCheckbox.
In comparison to that for a "rich:select":
A test of
{code}document.getElementById("form:tree:treeModelAdapter.0:treeNodeOptionSelectorInput"){code}
evaluates to the rich:select, while a test of {code}RichFaces.$(
document.getElementById("form:tree:treeModelAdapter.0:treeNodeOptionSelectorInput")
){code} evaluates to the component (source) itself, since
{code}element[richfaces.RICH_CONTAINER]{code} is defined.
So I think there are basically 2 problems in this case:
# The JavaScript code for evaluating the event source component in
{code}searchForComponentRootOrReturn(sourceElement);{code} is wrong in this
context, because it only searches for richfaces components. If {code}if
(sourceElement.id && !richfaces.$(sourceElement)) {{code} would evaluate to the
selectBooleanCheckbox as a valid event source, the search for the parent (which
in turn produces the problem with the ids) would not be required.
# The JavaScript code should respect the component separator while searching
for parents to avoid identifying the wrong component in case of similar ids.
was (Author: michaelb80):
[~bleathem] meanwhile I've tried the 2 things you asked for - although the ID
for the second test has to be a little different.
bq. 1. Replace the JSF <h:selectBooleanCheckbox> with a RichFaces component?
I've replaced the selectBooleanCheckbox with a rich:select and an a4j:ajax
event="selectitem". In this case the event is fired correctly - even if the ids
are similar. The reason for that is, that the select has the
{code}element[richfaces.RICH_CONTAINER]{code} and so a search for a parent is
not required.
bq. 2. Check what
RichFaces.$(document.getElementById("form:treeNode:treeNodeSelectBox"))
evaluates to?
Since a treeNode cannot be used without a valid tree around, a valid id will be
"form:tree:treeModelAdapter.0:treeNodeSelectBox".
A test of
{code}document.getElementById("form:tree:treeModelAdapter.0:treeNodeSelectBox"){code}
evaluates to the checkbox, while a test of {code}RichFaces.$(
document.getElementById("form:tree:treeModelAdapter.0:treeNodeSelectBox")
){code} evaluates to 'undefined', since
{code}element[richfaces.RICH_CONTAINER]{code} is not defined for the
selectBooleanCheckbox.
In comparison to that for a "rich:select":
A test of
{code}document.getElementById("form:tree:treeModelAdapter.0:treeNodeOptionSelectorInput"){code}
evaluates to the rich:select, while a test of {code}RichFaces.$(
document.getElementById("form:tree:treeModelAdapter.0:treeNodeOptionSelectorInput")
){code} evaluates to the component (source) itself, since
{code}element[richfaces.RICH_CONTAINER]{code} is defined.
So I think there are basically 2 problems in this case:
# The JavaScript code for evaluating the event source component in
{code}searchForComponentRootOrReturn(sourceElement);{code} is wrong in this
context, because it only searches for richfaces components. If {code}if
(sourceElement.id && !isRichFacesComponent(sourceElement)) {{code} would
evaluate to the selectBooleanCheckbox as a valid event source, the search for
the parent (which in turn produces the problem with the ids) would not be
required.
# The JavaScript code should respect the component separator while searching
for parents to avoid identifying the wrong component in case of similar ids.
> a4j:ajax problem with hierarchical component IDs
> ------------------------------------------------
>
> Key: RF-13776
> URL: https://issues.jboss.org/browse/RF-13776
> Project: RichFaces
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: component-a4j-core
> Affects Versions: 4.3.7
> Environment: RichFaces 4.3.7
> Mojarra 2.1.29
> Java 7 Update 67 (x64)
> Tomcat 7.0.52 (x64)
> Reporter: Michael B
>
> 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:
> {code:title=Snippet|borderStyle=solid}
> <rich:treeNode id="treeNode">
> <h:selectBooleanCheckbox id="treeNodeSelectBox">
> <a4j:ajax event="click" execute="@this"
> listener="#{someManagedBean.onCheckboxClick}" />
> </h:selectBooleanCheckbox>
> </rich:treeNode>
> {code}
> 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).
> {code:title=RichFaces JS-Snippet|borderStyle=solid}
> 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;
> };
> {code}
> 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)
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)
_______________________________________________
richfaces-issues mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/richfaces-issues