You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Johannes Odland (Created) (JIRA)" <ji...@apache.org> on 2012/02/21 11:15:34 UTC
[jira] [Created] (WICKET-4424) getComponentFromLastRenderedPage
appends componentInPage id when it shouldn't
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
[jira] [Resolved] (WICKET-4424) getComponentFromLastRenderedPage
appends componentInPage id when it shouldn't
Posted by "Martin Grigorov (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/WICKET-4424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Grigorov resolved WICKET-4424.
-------------------------------------
Resolution: Fixed
Fix Version/s: 6.0.0
1.5.5
Assignee: Martin Grigorov
The code now is a bit smarter and checks whether the developer already prepended the path with the auto-generated component id and do no prepend it automacally anymore.
Additionally I added javadoc explaining how to find a child component inside the started component.
Please try latest -SNAPSHOT and give feedback.
> 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
> Assignee: Martin Grigorov
> Priority: Minor
> Fix For: 1.5.5, 6.0.0
>
>
> 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