You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2017/10/02 08:18:00 UTC

[jira] [Commented] (WICKET-6461) Default constructor is incorrectly called if optional param is not provided in parameter placeholder URL with additional required parameter

    [ https://issues.apache.org/jira/browse/WICKET-6461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16187747#comment-16187747 ] 

ASF subversion and git services commented on WICKET-6461:
---------------------------------------------------------

Commit 2283dc502fca56f9e912823a4f94a629188aa63f in wicket's branch refs/heads/WICKET-6105-java.time from [~svenmeier]
[ https://git-wip-us.apache.org/repos/asf?p=wicket.git;h=2283dc5 ]

WICKET-6461 don't consume segments for optional parameters if required parameters are following


> Default constructor is incorrectly called if optional param is not provided in parameter placeholder URL with additional required parameter
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-6461
>                 URL: https://issues.apache.org/jira/browse/WICKET-6461
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 6.22.0
>            Reporter: Melissa Beldman
>            Assignee: Sven Meier
>             Fix For: 8.0.0-M8, 7.10.0
>
>         Attachments: quickstartPP.zip
>
>
> From the documentation here:
> https://ci.apache.org/projects/wicket/guide/6.x/guide/urls.html
> I'm following the section titled, "Using parameter placeholders with mounted pages".
> In the documentation from here:
> https://cwiki.apache.org/confluence/display/WICKET/Request+mapping
> {code}
> Named parameters - /page/${named1}/${named2}
> mountPage("/page/${named1}/${named2}", MyPage.class);
> Now a request to "/page/a/b" will be handled by MyPage and the parameters can be get with PageParameters.get(String) (e.g. parameters.get("named1") will return "a")
> Optional named parameters - /page/${named1}/#{named2\
> mountPage("/page/${named1}/#{named2}", MyPage.class);
> This means the second parameter is optional. Requests to "/page/a/b" , "/page/a/b/" and "/page/a/" will be handled by MyPage and the parameters can be get with PageParameters.get(String) (e.g. parameters.get("named2") will return "b" for the first case and null for the second).
> The mapper is smart enough to handle optional named parameters in any segment, not just the last one.
> {code}
> it states: "The mapper is smart enough to handle optional named parameters in any segment, not just the last one."
> I've found it does matter IF other segments in the url are also parameter placeholders. The resulting behaviour is that if the optional parameter placeholder isn't provided in the URL, the page's default constructor gets called instead of the PageParameter constructor as expected (since there are still additional PageParameter data that may need to be processed by the page). 
> Here is my example:
> From child class of AdtAuthenticatedWebApplication
> {code}
> @Override
> protected void init() 
> {
>     super.init();
>     mountPage("/foo/#{optParam}/${otherParam}", MyPage.class);
>     //mountPage("/foo/${otherParam}/#{optParam}",  MyPage.class); <--- NOTE: This works as expected
> }
> {code}
> In child class of WebPage
> {code}
> public class MyPage extends WebPage
> {
>     public MyPage(PageParameters parameters) 
>     {
>         super(parameters);
>         StringValue optParam = parameters.get("optParam");
>         StringValue otherParam = parameters.get("otherParam");
>        //do something...
>     }
>     private MyPage()
>     {        
>         throw new IllegalAccessError("The default constructor should not be instantiated");
>     }
> {code}
> And in a different class:
> {code}
> public static BookmarkablePageLink getBookmarkableLink(String id, String optParam, String otherParam)
>  {         
>         PageParameters pageParam = new PageParameters();
>                 
>         pageParam.add("otherParam", otherParam);
>         if (optParam != null && !optParam.isEmpty())
>         {
>             pageParam.add("optParam", optParam);
>         }
>                 
>         return new BookmarkablePageLink(id, MyPage.class, pageParam);             
>     } 
> {code}
> Here are the result of clicking on the BookmarkablePageLinks created:
> {code}
> /foo/baz/bar  -- calls MyPage(PageParameters parameters) constructor
> /foo/bar -- attempts to call MyPage default constructor (exception thrown)
> {code}
> Exception thrown is:
> {code}
> Last cause: Class org.apache.wicket.session.DefaultPageFactory can not access a member of class ca.example.for.testing.MyPage with modifiers "private"
> WicketMessage: Can't instantiate page using constructor 'private ca.example.for.testing.MyPage()'. This constructor is private!
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)