getComponentFromLastRenderedPage appends componentInPage id when it shouldn't
-----------------------------------------------------------------------------
Key: WICKET-4424
URL: https://issues.apache.org/jira/browse/WICKET-4424
Project: Wicket
Issue Type: Bug
Components: wicket
Affects Versions: 1.5.4
Reporter: Johannes Odland
Priority: Minor
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() {}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira