[ 
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

        

Reply via email to