Wicket
  1. Wicket
  2. WICKET-3554

Constructor of org.apache.wicket.PageReference should be public

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4.15
    • Fix Version/s: 1.5.6, 6.0.0-beta1
    • Component/s: wicket
    • Labels:
      None

      Description

      The construcor of PageReference is not accessible (no qualifier, proteced). Is this for a reason? As far as I can see, a public qualifier would be nice as I rather often created an own class with a similar implementation (because I could not create an instance of PageReference).

        Activity

        Hide
        Martin Grigorov added a comment -

        OK. I don't see a big problem if we make it public.

        Show
        Martin Grigorov added a comment - OK. I don't see a big problem if we make it public.
        Hide
        Erik Godding Boye added a comment -

        Let me take a step back and try to explain what I am trying to do.

        I want to achieve page navigation more or less as explained in this thread: http://apache-wicket.1842946.n4.nabble.com/How-to-get-request-page-in-Wicket-1-5-td3827411.html#a3830270
        When the page is used in an non-bookmarkable context, I pass in the reference to the referring page using PageReference - as shown in Igors response.
        The page reference is stored internally in the page (standard java field), and when it is time to go back, I use setResponsePage(pageReference.getPage()).

        But I also want to use the page in a bookmarkable context, but because of the package-protected constructor in PageReference, there is no way to construct a PageReference object from the parameters.

        Show
        Erik Godding Boye added a comment - Let me take a step back and try to explain what I am trying to do. I want to achieve page navigation more or less as explained in this thread: http://apache-wicket.1842946.n4.nabble.com/How-to-get-request-page-in-Wicket-1-5-td3827411.html#a3830270 When the page is used in an non-bookmarkable context, I pass in the reference to the referring page using PageReference - as shown in Igors response. The page reference is stored internally in the page (standard java field), and when it is time to go back, I use setResponsePage(pageReference.getPage()). But I also want to use the page in a bookmarkable context, but because of the package-protected constructor in PageReference, there is no way to construct a PageReference object from the parameters.
        Hide
        Tom Götz added a comment -

        And what is the advantage of your proposed approach? As Martin pointed out, there indeed is already a working solution for that usecase.

        Show
        Tom Götz added a comment - And what is the advantage of your proposed approach? As Martin pointed out, there indeed is already a working solution for that usecase.
        Hide
        Martin Grigorov added a comment -

        Store it where ?
        If you use PageReference instead of pageId in the parameters then it wont be bookmarkable anymore.

        Show
        Martin Grigorov added a comment - Store it where ? If you use PageReference instead of pageId in the parameters then it wont be bookmarkable anymore.
        Hide
        Erik Godding Boye added a comment -

        Sort, of yes. I am planning to store the PageReference (instead of the numeric page id, as I do now), and then use the PageReference#getPage to get the user back to the referring page.

        Show
        Erik Godding Boye added a comment - Sort, of yes. I am planning to store the PageReference (instead of the numeric page id, as I do now), and then use the PageReference#getPage to get the user back to the referring page.
        Hide
        Martin Grigorov added a comment -

        So you bring the page id in the request parameters and you prefer to call:

        page = new PageReference(pageIdInt).getPage()

        instead of

        page = getSession().getPageManager().getPage(pageIdInt)
        ?

        If there is no page with such id in the current session then expect PageExpiredException instead of null. I'll document this.

        Show
        Martin Grigorov added a comment - So you bring the page id in the request parameters and you prefer to call: page = new PageReference(pageIdInt).getPage() instead of page = getSession().getPageManager().getPage(pageIdInt) ? If there is no page with such id in the current session then expect PageExpiredException instead of null. I'll document this.
        Hide
        Erik Godding Boye added a comment -

        I think this issue should be reopened. Let me try to explain why:

        I am trying to pass a reference to the referring page, to a bookmarkable page, using a BookmarkablePageLink. The reference is later used to direct the user back to the referring page (if it still exists).
        Because of the non-public constructor in PageReference, there is no way to reconstruct the object based on the PageParameters passed to the bookmarkable page.

        Of course I have to deal with the possibility that the referring page no longer exist, but I guess in that case, PageReference#getPage will return null.

        As a workaround, I store the pageId as a reference to the referring page in the bookmarkable page, and copied the code in PageReference#getPage. It works, but it is definitely not an ideal solution.

        I you are worried about creating references to non-existing pages, you could add some kind of validating factory method - that verifies the page existence (using the same code as in PageReference#getPage).

        Show
        Erik Godding Boye added a comment - I think this issue should be reopened. Let me try to explain why: I am trying to pass a reference to the referring page, to a bookmarkable page, using a BookmarkablePageLink. The reference is later used to direct the user back to the referring page (if it still exists). Because of the non-public constructor in PageReference, there is no way to reconstruct the object based on the PageParameters passed to the bookmarkable page. Of course I have to deal with the possibility that the referring page no longer exist, but I guess in that case, PageReference#getPage will return null. As a workaround, I store the pageId as a reference to the referring page in the bookmarkable page, and copied the code in PageReference#getPage. It works, but it is definitely not an ideal solution. I you are worried about creating references to non-existing pages, you could add some kind of validating factory method - that verifies the page existence (using the same code as in PageReference#getPage).
        Hide
        Tom Götz added a comment -

        Ok, mea culpa. I overlooked page.getPageReference(), thanks for the pointer!

        Show
        Tom Götz added a comment - Ok, mea culpa. I overlooked page.getPageReference(), thanks for the pointer!
        Hide
        Martin Grigorov added a comment -

        Why do you need to create it manually ?
        The idea is that you have a Page instance and you can pass a reference to it to another page by using: page.getPageReference().
        Having public constructor you may create a reference to non-existing page.

        Show
        Martin Grigorov added a comment - Why do you need to create it manually ? The idea is that you have a Page instance and you can pass a reference to it to another page by using: page.getPageReference(). Having public constructor you may create a reference to non-existing page.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Tom Götz
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development