Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4424

getComponentFromLastRenderedPage appends componentInPage id when it shouldn't

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.5.4
    • 1.5.5, 6.0.0-beta1
    • wicket
    • None

    Description

      When using WicketTester#startComponentInPage with a component class, wicket will instantiate the component and give it an id.

      As an example, a starting a panel with a link inside will generate these page relative paths:

      testObject
      testObject:link

      This id is automatically generated by wicket and not known to the developer, wich makes it impossible for the developer to reference components by path, as the first segment of the path is unknown.
      To remedy this, wicket appends the id of the component to the path given by the developer in getComponentFromLastRenderedPage().

      If the developer calls clickLink("link"), getComponentFromLastRenderedPage will append the generated id and form the path "testObject:link"

      This is OK as long as the developer explicitly gives the path, omitting the id of the component.

      But, when retrieving the path from the components themselves this creates a problem.
      Say a developer is iterating through all links in the page and clicking them:

      Link link = getLink();
      wicketTester.clickLink(link.getPageRelativePath());

      ClickLink is then called with the path "testObject:link", and getComponentFromLastRenderedPage will append the generated id forming the path "testObject:testObject:link" wich clearly fails.

      This is illustrated by a simple testcase:

      @Test
      public void clickShouldWork() {
      WicketTester tester = new WicketTester();
      tester.startComponentInPage(TestLink.class);
      Link link = (Link) tester.getLastRenderedPage().get(0);
      String path = link.getPageRelativePath();
      wicketTester.clickLink(path);
      }

      public static class TestLink extends Link {
      public TestLink(String id)

      { super(id);}

      public void onClick() {}
      }

      Attachments

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            johannes.odland@gmail.com Johannes Odland
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: