You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dmitry Kandalov <no...@gmail.com> on 2007/11/09 22:15:38 UTC

bookmarkable page with one instance per session

Hi,

I was recently wondering is there request coding strategy which would allow me 
to have one page instance of certain class per session, so after requesting 
mounted url user would always use the same page instance or a new one would 
be created if there was no instance of that class.

One of the reasons I thought about it is because I wanted "very nice" urls, so 
that after clicking links/ submitting forms url would remain exactly the same 
as mount. And another reason is that I wanted to be able to return to the 
page without passing its instance to another page.

Do you think such coding strategy is sensible?


I actually tried to implement it by extending 
AbstractRequestTargetUrlCodingStrategy. The idea was that I would have one 
pagemap for each mounted page and in the pagemap there would be the only 
instance of that page. Here is some naive code:

private final String pagemapName;
...
public IRequestTarget decode(RequestParameters requestParameters) {
    final IPageMap pageMap = PageMap.forName(pagemapName);

    // didn't find how to get the latest version of the page
    if (pageMap.containsPage(0, 0)) {
        final Page page = pageMap.get(0, 0);
        return new PageRequestTarget(page);
    } else {
        // the page created by this bookmarkable target is not in the 
        // pagemap "pagemapName", didn't find how to put it there
        return new BookmarkablePageRequestTarget(pagemapName, pageClass);
    }
}


ps sorry if such strategy is already there and I just didn't understand it's 
what I want

Dima

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: bookmarkable page with one instance per session

Posted by Dmitry Kandalov <no...@gmail.com>.
On Sunday 11 November 2007 14:29:02 Dmitry Kandalov wrote:
> return new BookmarkablePageRequestTarget(pagemapName, pageClass) {
>     protected Page newPage(Class pageClass, RequestCycle requestCycle) {
>         final Page page = super.newPage(pageClass, requestCycle);
>         page.setPageMap(pageMap); // can't actually do it
>         return page;
>     }
> };
>
> In this case there would be no need for IPageFactory which is aware of
> mounts.

Nevermind. It was a bad idea.


Dima

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: bookmarkable page with one instance per session

Posted by Dmitry Kandalov <no...@gmail.com>.
On Sunday 11 November 2007 14:36:10 Johan Compagner wrote:
> why do you want to move it to another pagemap? the probelm is that you
> cant do that because then the other browser instance cant find it
> anymore or that on is also changing and accessing the same page, in
> 1.3 you are then better of by not using pagemaps

Sorry, I somehow didn't see your message and replied to myself. I tried to 
store pages in the pagemap so that not to depend on my session 
implementation, but you're right it doesn't work well.


Dima

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: bookmarkable page with one instance per session

Posted by Johan Compagner <jc...@gmail.com>.
why do you want to move it to another pagemap? the probelm is that you
cant do that because then the other browser instance cant find it
anymore or that on is also changing and accessing the same page, in
1.3 you are then better of by not using pagemaps

On 11/11/07, Dmitry Kandalov <no...@gmail.com> wrote:
> On Saturday 10 November 2007 03:49:51 Johan Compagner wrote:
> > wicket doesn't have support for these kind of pages (yet)
>
> Does "yet" mean it's planned/ in progress?
>
> > You have to implement that yourself. You could have a map of pages per
> > class in your session and resolve to them. You can do that with creating
> > your own IPageFactory
> > Which the first looks in the current session
>
> Thanks, Johan. I wrapped DefaultPageFactory and now everything works just as
> I
> wanted. I didn't really expect it would be so easy to implement :)
>
> It's not a problem for me, but may be it would be a bit simpler if it was
> possible to do this:
>
> return new BookmarkablePageRequestTarget(pagemapName, pageClass) {
>     protected Page newPage(Class pageClass, RequestCycle requestCycle) {
>         final Page page = super.newPage(pageClass, requestCycle);
>         page.setPageMap(pageMap); // can't actually do it
>         return page;
>     }
> };
>
> In this case there would be no need for IPageFactory which is aware of
> mounts.
>
>
> Dima
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: bookmarkable page with one instance per session

Posted by Dmitry Kandalov <no...@gmail.com>.
On Saturday 10 November 2007 03:49:51 Johan Compagner wrote:
> wicket doesn't have support for these kind of pages (yet)

Does "yet" mean it's planned/ in progress?

> You have to implement that yourself. You could have a map of pages per
> class in your session and resolve to them. You can do that with creating
> your own IPageFactory
> Which the first looks in the current session

Thanks, Johan. I wrapped DefaultPageFactory and now everything works just as I 
wanted. I didn't really expect it would be so easy to implement :)

It's not a problem for me, but may be it would be a bit simpler if it was 
possible to do this:

return new BookmarkablePageRequestTarget(pagemapName, pageClass) {
    protected Page newPage(Class pageClass, RequestCycle requestCycle) {
        final Page page = super.newPage(pageClass, requestCycle);
        page.setPageMap(pageMap); // can't actually do it
        return page;
    }
};

In this case there would be no need for IPageFactory which is aware of mounts.


Dima

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: bookmarkable page with one instance per session

Posted by Johan Compagner <jc...@gmail.com>.
wicket doesn't have support for these kind of pages (yet)

You have to implement that yourself. You could have a map of pages per class
in your session and resolve to them. You can do that with creating your own
IPageFactory
Which the first looks in the current session

johan

On Nov 9, 2007 10:15 PM, Dmitry Kandalov <no...@gmail.com> wrote:

> Hi,
>
> I was recently wondering is there request coding strategy which would
> allow me
> to have one page instance of certain class per session, so after
> requesting
> mounted url user would always use the same page instance or a new one
> would
> be created if there was no instance of that class.
>
> One of the reasons I thought about it is because I wanted "very nice"
> urls, so
> that after clicking links/ submitting forms url would remain exactly the
> same
> as mount. And another reason is that I wanted to be able to return to the
> page without passing its instance to another page.
>
> Do you think such coding strategy is sensible?
>
>
> I actually tried to implement it by extending
> AbstractRequestTargetUrlCodingStrategy. The idea was that I would have one
> pagemap for each mounted page and in the pagemap there would be the only
> instance of that page. Here is some naive code:
>
> private final String pagemapName;
> ...
> public IRequestTarget decode(RequestParameters requestParameters) {
>    final IPageMap pageMap = PageMap.forName(pagemapName);
>
>    // didn't find how to get the latest version of the page
>    if (pageMap.containsPage(0, 0)) {
>        final Page page = pageMap.get(0, 0);
>        return new PageRequestTarget(page);
>    } else {
>        // the page created by this bookmarkable target is not in the
>        // pagemap "pagemapName", didn't find how to put it there
>        return new BookmarkablePageRequestTarget(pagemapName, pageClass);
>    }
> }
>
>
> ps sorry if such strategy is already there and I just didn't understand
> it's
> what I want
>
> Dima
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>