Wicket
  1. Wicket
  2. WICKET-1258

AjaxFormChoiceComponentUpdatingBehavior assumes Radio/Choice items are a direct child of the group in the client-side DOM

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.0-final
    • Fix Version/s: 1.3.1
    • Component/s: wicket
    • Labels:
      None

      Description

      In the reference behavior, the attachFormChoiceHandlers javascript function being rendered in onRenderHead incorrectly assumes that the individual choices we're attaching events to (the Radio or CheckBox components) are direct children of the group.

      64) asb.append("function attachChoiceHandlers(markupid, callbackscript) {\n");
      65) asb.append(" var choiceElement = document.getElementById(markupid);\n");
      66) asb.append(" for( var x = 0; x < choiceElement.childNodes.length; x++ ) {\n");
      67) asb.append(" if (choiceElement.childNodes[x] && choiceElement.childNodes[x].tagName) {\n");
      68) asb.append(" var tag = choiceElement.childNodes[x].tagName.toLowerCase();\n");
      69) asb.append(" if (tag == 'input')

      {\n"); 70) asb.append(" Wicket.Event.add(choiceElement.childNodes[x],'click', callbackscript);"); 71) asb.append(" }

      \n");
      72) asb.append(" }\n");
      73) asb.append(" }\n");
      74) asb.append("}\n");

      The problem is the loop on line 66 - it only loops through direct child nodes, when in reality there could be other elements (like spans) in between the RadioGroup and the Radio in the dom, especially if for some reason the Radio was included as a part of another Component, which was actually added to the RadioGroup.

      The fix should be simple, but I don't know the appropriate Wicket-approved function of recursing through children in the client-side.

      As a side note, is there a reason this recursion is done on the client-side rather than on the server-side?

        Issue Links

          Activity

          Hide
          Matt Clark added a comment -

          FYI - I think we figured out why it's done on the server-side, and that might be because of the interactions with ListView and other MarkupContainers who might be modifying the structure of the component hierarchy after the behavior's renderHead method. So the remaining problem is just that the client-side javscript referenced above does not recurse through all descendants, it's just looking at immediate children.

          Show
          Matt Clark added a comment - FYI - I think we figured out why it's done on the server-side, and that might be because of the interactions with ListView and other MarkupContainers who might be modifying the structure of the component hierarchy after the behavior's renderHead method. So the remaining problem is just that the client-side javscript referenced above does not recurse through all descendants, it's just looking at immediate children.
          Hide
          Igor Vaynberg added a comment -

          johan, this one is yours right?

          Show
          Igor Vaynberg added a comment - johan, this one is yours right?

            People

            • Assignee:
              Igor Vaynberg
              Reporter:
              Matt Clark
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development