You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Xavier López <xa...@gmail.com> on 2010/04/16 10:37:49 UTC

Detect bookmark access to nonbookmarkablepages

Hi there,

I'm trying to find an elegant way to detect the cases where a user tries to
access a nonbookmarkablepage with a bookmark. From the stack trace produced
in this case, I see this situation is handled in
DefaultPageFactory#newPage(Class pageClass), like this:

            ....
            catch (NoSuchMethodException e)
        {
            // a bit of a hack here..
            Constructor constructor = constructor(pageClass,
PageParameters.class);
            if (constructor != null)
            {
                return newPage(constructor, new PageParameters());
            }
            else
            {
                throw new WicketRuntimeException("Unable to create page from
" + pageClass +
                        ". Class does not have a default contructor", e);
            }
        }


I would like to present a custom page explaining the circumstances with a
nice link to the starting place where to navigate from.
I don't really like treating this situation as a WicketRuntimeException and
have it bubbling up to an internalerrorpage, because of the little
information on the exception thrown (i don't like identifying it by its
text, or nested exception type).

Unfortunately, DefaultPageFactory#newPage(Class pageClass) is final, so this
behavior can not be overriden. Is providing a custom implementation of
IPageFactory the best approach to this issue ? Any other way around ?

Cheers,
Xavier

Re: Detect bookmark access to nonbookmarkablepages

Posted by Xavier López <xa...@gmail.com>.
Thanks for the feedback, Igor, nice idea.

About the page factory exception, in fact I have nonbookmarkablepages
mounted as if they were, just to makeup the url's, like this:

mount(new HybridUrlCodingStrategy("/pageA", PageA.class));

So that when the user enters PageA (no default constructor - non
bookmarkable), he gets on the browser's location bar:
http://myapplication/pageA[.x]

Maybe it's a little weird, but it's working for me :)

Cheers,
Xavier

2010/4/16 Igor Vaynberg <ig...@gmail.com>

> use a decorator, wrap the default factory, catch the exception,
> transform it into something else.
>
> although, if your users are bookmarking a non-bookmarkable url you
> should get a page expired error. page factory is only used for
> creating bookmarkable pages.
>
> -igor
>
> On Fri, Apr 16, 2010 at 1:37 AM, Xavier López <xa...@gmail.com> wrote:
> > Hi there,
> >
> > I'm trying to find an elegant way to detect the cases where a user tries
> to
> > access a nonbookmarkablepage with a bookmark. From the stack trace
> produced
> > in this case, I see this situation is handled in
> > DefaultPageFactory#newPage(Class pageClass), like this:
> >
> >            ....
> >            catch (NoSuchMethodException e)
> >        {
> >            // a bit of a hack here..
> >            Constructor constructor = constructor(pageClass,
> > PageParameters.class);
> >            if (constructor != null)
> >            {
> >                return newPage(constructor, new PageParameters());
> >            }
> >            else
> >            {
> >                throw new WicketRuntimeException("Unable to create page
> from
> > " + pageClass +
> >                        ". Class does not have a default contructor", e);
> >            }
> >        }
> >
> >
> > I would like to present a custom page explaining the circumstances with a
> > nice link to the starting place where to navigate from.
> > I don't really like treating this situation as a WicketRuntimeException
> and
> > have it bubbling up to an internalerrorpage, because of the little
> > information on the exception thrown (i don't like identifying it by its
> > text, or nested exception type).
> >
> > Unfortunately, DefaultPageFactory#newPage(Class pageClass) is final, so
> this
> > behavior can not be overriden. Is providing a custom implementation of
> > IPageFactory the best approach to this issue ? Any other way around ?
> >
> > Cheers,
> > Xavier
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
"Klein bottle for rent--inquire within."

Re: Detect bookmark access to nonbookmarkablepages

Posted by Igor Vaynberg <ig...@gmail.com>.
use a decorator, wrap the default factory, catch the exception,
transform it into something else.

although, if your users are bookmarking a non-bookmarkable url you
should get a page expired error. page factory is only used for
creating bookmarkable pages.

-igor

On Fri, Apr 16, 2010 at 1:37 AM, Xavier López <xa...@gmail.com> wrote:
> Hi there,
>
> I'm trying to find an elegant way to detect the cases where a user tries to
> access a nonbookmarkablepage with a bookmark. From the stack trace produced
> in this case, I see this situation is handled in
> DefaultPageFactory#newPage(Class pageClass), like this:
>
>            ....
>            catch (NoSuchMethodException e)
>        {
>            // a bit of a hack here..
>            Constructor constructor = constructor(pageClass,
> PageParameters.class);
>            if (constructor != null)
>            {
>                return newPage(constructor, new PageParameters());
>            }
>            else
>            {
>                throw new WicketRuntimeException("Unable to create page from
> " + pageClass +
>                        ". Class does not have a default contructor", e);
>            }
>        }
>
>
> I would like to present a custom page explaining the circumstances with a
> nice link to the starting place where to navigate from.
> I don't really like treating this situation as a WicketRuntimeException and
> have it bubbling up to an internalerrorpage, because of the little
> information on the exception thrown (i don't like identifying it by its
> text, or nested exception type).
>
> Unfortunately, DefaultPageFactory#newPage(Class pageClass) is final, so this
> behavior can not be overriden. Is providing a custom implementation of
> IPageFactory the best approach to this issue ? Any other way around ?
>
> Cheers,
> Xavier
>

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