Wicket
  1. Wicket
  2. WICKET-4874

"Cannot find element with id" error seen in Ajax Debug for child of wicket:enclosure

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 6.3.0
    • Fix Version/s: 7.0.0-M1
    • Component/s: wicket
    • Environment:
      Windows 7 x64 Java 1.6.0_32

      Description

      When an AjaxLink is hidden due to being a child of a wicket:enclosure an error is seen in the Ajax Debug window. It seems like the event handler is expecting the AjaxLink to exist in the DOM even though it has been hidden.

        Issue Links

          Activity

          Jesse Bonzo created issue -
          Hide
          Jesse Bonzo added a comment -

          This project demonstrates the problem

          Show
          Jesse Bonzo added a comment - This project demonstrates the problem
          Jesse Bonzo made changes -
          Field Original Value New Value
          Attachment WicketQuickStart.zip [ 12554563 ]
          Hide
          Andrea Del Bene added a comment -

          I think the problem is due to the adoption in Wicket 6 of browser event registration in place of inline events. Now the AJAX behaviour tries to register the ajax handler for the given component but it fails as the component is not rendered (is inside wicket:enclosure ) and at the same time is visible in hierachy. I didn't find a solution yet.

          Show
          Andrea Del Bene added a comment - I think the problem is due to the adoption in Wicket 6 of browser event registration in place of inline events. Now the AJAX behaviour tries to register the ajax handler for the given component but it fails as the component is not rendered (is inside wicket:enclosure ) and at the same time is visible in hierachy. I didn't find a solution yet.
          Hide
          Jesse Bonzo added a comment -

          A workaround is to override isVisible for the link, returning dropdown.isVisible(). No errors are shown when I do this.

          Show
          Jesse Bonzo added a comment - A workaround is to override isVisible for the link, returning dropdown.isVisible(). No errors are shown when I do this.
          Hide
          Martin Grigorov added a comment -

          I don't use <wicket:enclosure> in my applications and I highly recommend you to avoid using it too!

          I recommend to use the non-auto component org.apache.wicket.markup.html.basic.EnclosureContainer instead.

          markup:
          coming up is some invisible stuff!
          <div wicket:id="enclosure">
          <select wicket:id="dropdown"></select>
          <a wicket:id="link">click me!</a>
          </div>

          java code:
          DropDownChoice<String> dropdown = new DropDownChoice<String>("dropdown")

          { ... };

          EnclosureContainer enclosureContainer = new EnclosureContainer("enclosure", dropdown);
          add(enclosureContainer);
          enclosureContainer.add(dropdown);

          AjaxLink<Void> link = new AjaxLink<Void>("link") { ... }

          ;
          enclosureContainer.add(link);

          Works as one would expect!

          The problem with wicket:enclosure is that it is an auto component which is resolved during rendering. The children components inside don't know anything about it. They don't know its existence in the hierarchy. AjaxEventBehavior#renderHead() wont be called at all if there was indication that a parent in the hierarchy is invisible. But unfortunately this knowledge comes too late.

          Show
          Martin Grigorov added a comment - I don't use <wicket:enclosure> in my applications and I highly recommend you to avoid using it too! I recommend to use the non-auto component org.apache.wicket.markup.html.basic.EnclosureContainer instead. markup: coming up is some invisible stuff! <div wicket:id="enclosure"> <select wicket:id="dropdown"></select> <a wicket:id="link">click me!</a> </div> java code: DropDownChoice<String> dropdown = new DropDownChoice<String>("dropdown") { ... }; EnclosureContainer enclosureContainer = new EnclosureContainer("enclosure", dropdown); add(enclosureContainer); enclosureContainer.add(dropdown); AjaxLink<Void> link = new AjaxLink<Void>("link") { ... } ; enclosureContainer.add(link); Works as one would expect! The problem with wicket:enclosure is that it is an auto component which is resolved during rendering. The children components inside don't know anything about it. They don't know its existence in the hierarchy. AjaxEventBehavior#renderHead() wont be called at all if there was indication that a parent in the hierarchy is invisible. But unfortunately this knowledge comes too late.
          Hide
          Jesse Bonzo added a comment -

          That works for me. I will probably need to convert all of my wicket:enclosures to use EnclosureContainer to avoid this error.

          Show
          Jesse Bonzo added a comment - That works for me. I will probably need to convert all of my wicket:enclosures to use EnclosureContainer to avoid this error.
          Martin Grigorov made changes -
          Link This issue relates to WICKET-4382 [ WICKET-4382 ]
          Martin Grigorov made changes -
          Link This issue relates to WICKET-3947 [ WICKET-3947 ]
          Martin Grigorov made changes -
          Link This issue relates to WICKET-4700 [ WICKET-4700 ]
          Martin Grigorov made changes -
          Link This issue is duplicated by WICKET-5214 [ WICKET-5214 ]
          Martin Grigorov made changes -
          Link This issue is duplicated by WICKET-3947 [ WICKET-3947 ]
          Martin Grigorov made changes -
          Link This issue is duplicated by WICKET-4700 [ WICKET-4700 ]
          Martin Grigorov made changes -
          Link This issue is duplicated by WICKET-4382 [ WICKET-4382 ]
          Martin Grigorov made changes -
          Remote Link This issue links to "Discussion in dev@ about deprecating <wicket:enclosure> (Web Link)" [ 12348 ]
          Martin Grigorov made changes -
          Link This issue relates to WICKET-5479 [ WICKET-5479 ]
          Hide
          Martin Grigorov added a comment -

          The problem is solved by using the new queueing functionality implemented for WICKET-3335.

          In the attached quickstart replace

          add(dropdown); and add(link);

          with

          queue(dropdown); and queue(link);

          This way the 'link' is resolved as a child of the enclosure and is invisible as desired.

          Show
          Martin Grigorov added a comment - The problem is solved by using the new queueing functionality implemented for WICKET-3335 . In the attached quickstart replace add(dropdown); and add(link); with queue(dropdown); and queue(link); This way the 'link' is resolved as a child of the enclosure and is invisible as desired.
          Martin Grigorov made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Igor Vaynberg [ ivaynberg ]
          Fix Version/s 7.0.0 [ 12322958 ]
          Resolution Fixed [ 1 ]
          Hide
          Rudi Wijaya added a comment -

          I also got hit by this bug (actually WICKET-5214: ignored unrendered components) and spent some time being confused about this behavior.

          I agree with Adrian Sandor's suggestion that any use of <wicket:enclosure> should log a WARN and mention this ticket (WICKET-4874 / WICKET-5214) and also suggesting EnclosureContainer instead.

          And hopefully <wicket:enclosure> is removed from Wicket 7.0 because it's harmful to "support" a feature with problematic/unpredictable behavior.

          Show
          Rudi Wijaya added a comment - I also got hit by this bug (actually WICKET-5214 : ignored unrendered components) and spent some time being confused about this behavior. I agree with Adrian Sandor 's suggestion that any use of <wicket:enclosure> should log a WARN and mention this ticket ( WICKET-4874 / WICKET-5214 ) and also suggesting EnclosureContainer instead. And hopefully <wicket:enclosure> is removed from Wicket 7.0 because it's harmful to "support" a feature with problematic/unpredictable behavior.
          Hide
          Rudi Wijaya added a comment -
          Show
          Rudi Wijaya added a comment - Tag Hendy Irawan
          Martin Grigorov made changes -
          Remote Link This issue links to "Discussion to deprecate <wicket:enclosure>in Wicket 7 (Web Link)" [ 15129 ]
          Hide
          Martin Grigorov added a comment -

          I've linked this ticket to the discussion at dev@ about deprecating <wicket:enclosure> in Wicket 7.x.
          The consensus was: wicket:enclosure works in 90% of the use cases so it should stay.

          Show
          Martin Grigorov added a comment - I've linked this ticket to the discussion at dev@ about deprecating <wicket:enclosure> in Wicket 7.x. The consensus was: wicket:enclosure works in 90% of the use cases so it should stay.
          Martin Grigorov made changes -
          Remote Link This issue links to "Discussion to deprecate <wicket:enclosure>in Wicket 7 (Web Link)" [ 15129 ]

            People

            • Assignee:
              Igor Vaynberg
              Reporter:
              Jesse Bonzo
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development