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

BaseWicketTester can't find the pageLink field using reflection when you override the PageLink class.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4-RC1
    • Fix Version/s: 1.4-RC2
    • Component/s: wicket
    • Labels:
      None

      Description

      Currently, BaseWicketTester (line 524) does this:

      public <C extends Page> Result isPageLink(String path, Class<C> expectedPageClass)
      {
      PageLink<?> pageLink = (PageLink<?>)getComponentFromLastRenderedPage(path);
      try

      { Field iPageLinkField = pageLink.getClass().getDeclaredField("pageLink"); iPageLinkField.setAccessible(true); IPageLink iPageLink = (IPageLink)iPageLinkField.get(pageLink); return isEqual(expectedPageClass, iPageLink.getPageIdentity()); }

      The problem manifests when you want to customize a page link's onClick by overriding it like this:

      new PageLink<AuthPage>("pageLink", AuthPage.class) {

      private static final long serialVersionUID = 1L;

      @Override
      public void onClick()

      { Foo.bar(); super.onClick(); }

      });

      As a result; the BaseWicketTester tries to look for the pageLink field in the anonymous class instead of the privately declared pageLink field in the PageLink class.

      BaseWicketTester should either go down the tree:

      for(Class type = pageLink.getClass(); type != Object.class; type = type.getSuperclass())

      Or a getter should be made for the pageLink field. (This is what Java wants you to do).

        Attachments

        1. pagelink.patch
          1 kB
          Maarten Billemont

          Activity

            People

            • Assignee:
              jdonnerstag Juegen Donnerstag
              Reporter:
              lhunath Maarten Billemont
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: