You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by John Patterson <jd...@gmail.com> on 2007/10/09 00:37:36 UTC

Custom URL strategy

Hi,

I want to build a custom url encoder fro bookmarkable pages and have  
been looking at BookmarkablePageRequestTargetUrlCodingStrategy.  Can  
someone quickly contrast the responsibilities of  
IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.  From a  
quick look it seems like they duplicate some of the encoding/decoding  
functionality.

If I want to change the way URL's are translated for every  
bookmarkable page (including which page to create) should I override  
WebRequestCodingStrategy.encode()/decode()?

Cheers,

John

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


Re: Custom URL strategy

Posted by John Patterson <jd...@gmail.com>.
Nice one.  Cheers for your explanations.  I am getting there slowly.

On 9 Oct 2007, at 14:25, Matej Knopp wrote:

> Hi, see the response below
>
> On 10/9/07, John Patterson <jd...@gmail.com> wrote:
>> Hi,
>>
>> As I am figuring out how to create my own IRequestCodingStrategy I
>> have come across a few things which seem be suspicious IMHO.  I could
>> be wrong with all of them but I thought I should bring them up...
>>
>> These are all in WebRequestCodingStrategy
>>
>> This code...
>>
>>         public final RequestParameters decode(final Request request)
>>         {
>>                         parameters.setPageMapName
>> (WebRequestCodingStrategy.decodePageMapName(request
>>                                 .getParameter(PAGEMAP)));
>>                  }
>>
>>
>>         ... calls RequestParameters ...
>>
>>         public void setPageMapName(String pageMapName)
>>         {
>>                 // this should be done in coding strategies, but  
>> its here as a
>>                 // precaution
>>                 this.pageMapName =  
>> WebRequestCodingStrategy.decodePageMapName
>> (pageMapName);
>>         }
>>
>> seems to decode the name twice.  It also seems to be getting set
>> again here ...
> Yeah, looks that way, the decoding should be only done in setPageMap
> name, good catch, although it doesn't really changes the behavior.
>>
>>
>>
>>         public static void addInterfaceParameters(final String
>> interfaceParameter,
>>                         final RequestParameters parameters)
>>         {
>>                 ...
>>
>>                 // Set pagemap name
>>                 final String pageMapName = pathComponents[0];
>>                 parameters.setPageMapName(pageMapName.length() == 0 ?
>> PageMap.DEFAULT_NAME : pageMapName);
>>
>>                 ...
>>         }
>>
>> This method seems to have old Javadoc stating that
>>
>>         /**
>>          * Adds bookmarkable page related parameters (page alias and
>> optionally page parameters). Any
>>          * bookmarkable page alias mount will override this  
>> method; hence if
>> a mount is found, this
>>          * method will not be called.
>>         protected void addBookmarkablePageParameters(final Request  
>> request,
>>
>> but it doesn't seem to do this any more and I think it is called
>> _before_ mounts are tried
> That might be true, but for mounted pages the method doesn't do
> anything, as there is no wicket:bookmarkablePage parameter inside URL.
>>
>> The interface IRequestTargetMountsInfo contains one method which is
>> not referenced anywhere in Wicket (maybe in wicketstuff?)
> Probably a left over from prior refactoring.
>>
>> It seems that the concept of handlers for coding URL's like   is
>> great but I wish it was used at the top level and not just for
>> mounted pages.
>
> Well, nothing should prevent you from writing your own strategy and in
> that strategy you can handle the mounted page as you wish. Just keep
> in mind there are many kinds of URLs, and your strategy has to support
> those.
>
> Anyway, we are aware that the URL coding/decoding is far from perfect
> and some parts are rather cumbersome. So it should be subject of a
> major refactor in the next release.
>
> -Matej
>
>>
>> What is bookmarkablePageClass doing in RequestParameters?  This seems
>> out of place considering it is passed in as an argument to
>> IRequestTargetUrlCodingStrategy which has the responsibility of
>> choosing and creating the type of target.
> Again, URL coding strategy is only for mounted pages. There are
> bookmarkable URLS even without mounted pages, and that is handled by
> WebRequestCodingStrategy.
>>
>> Maybe a good approach would be to iterate through all registered
>> handlers for each request until one can handle it.  The default
>> handling done in WebRequestCodingStrategy could simply be the last
>> handler in the chain.  Resources and mounts could be first by default
>> and users (like me) could add their own handlers.
>>
>> Anyway... just some thoughts while I am knee deep in the internals of
>> this area.
>>
>> John.
>>
>> On 9 Oct 2007, at 01:24, Matej Knopp wrote:
>>
>>> IIRC WebRequestCodingStrategy is used for non-mounted pages only and
>>> it delegates the encoding/decoding for mounted pages to
>>> IRequestTargetUrlCodingStrategy.
>>>
>>> -Matej
>>>
>>> On 10/9/07, John Patterson <jd...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I want to build a custom url encoder fro bookmarkable pages and  
>>>> have
>>>> been looking at BookmarkablePageRequestTargetUrlCodingStrategy.   
>>>> Can
>>>> someone quickly contrast the responsibilities of
>>>> IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.   
>>>> From a
>>>> quick look it seems like they duplicate some of the encoding/ 
>>>> decoding
>>>> functionality.
>>>>
>>>> If I want to change the way URL's are translated for every
>>>> bookmarkable page (including which page to create) should I  
>>>> override
>>>> WebRequestCodingStrategy.encode()/decode()?
>>>>
>>>> Cheers,
>>>>
>>>> John
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> 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
>>>
>>
>>
>
> ---------------------------------------------------------------------
> 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: Custom URL strategy

Posted by Matej Knopp <ma...@gmail.com>.
Hi, see the response below

On 10/9/07, John Patterson <jd...@gmail.com> wrote:
> Hi,
>
> As I am figuring out how to create my own IRequestCodingStrategy I
> have come across a few things which seem be suspicious IMHO.  I could
> be wrong with all of them but I thought I should bring them up...
>
> These are all in WebRequestCodingStrategy
>
> This code...
>
>         public final RequestParameters decode(final Request request)
>         {
>                         parameters.setPageMapName
> (WebRequestCodingStrategy.decodePageMapName(request
>                                 .getParameter(PAGEMAP)));
>                  }
>
>
>         ... calls RequestParameters ...
>
>         public void setPageMapName(String pageMapName)
>         {
>                 // this should be done in coding strategies, but its here as a
>                 // precaution
>                 this.pageMapName = WebRequestCodingStrategy.decodePageMapName
> (pageMapName);
>         }
>
> seems to decode the name twice.  It also seems to be getting set
> again here ...
Yeah, looks that way, the decoding should be only done in setPageMap
name, good catch, although it doesn't really changes the behavior.
>
>
>
>         public static void addInterfaceParameters(final String
> interfaceParameter,
>                         final RequestParameters parameters)
>         {
>                 ...
>
>                 // Set pagemap name
>                 final String pageMapName = pathComponents[0];
>                 parameters.setPageMapName(pageMapName.length() == 0 ?
> PageMap.DEFAULT_NAME : pageMapName);
>
>                 ...
>         }
>
> This method seems to have old Javadoc stating that
>
>         /**
>          * Adds bookmarkable page related parameters (page alias and
> optionally page parameters). Any
>          * bookmarkable page alias mount will override this method; hence if
> a mount is found, this
>          * method will not be called.
>         protected void addBookmarkablePageParameters(final Request request,
>
> but it doesn't seem to do this any more and I think it is called
> _before_ mounts are tried
That might be true, but for mounted pages the method doesn't do
anything, as there is no wicket:bookmarkablePage parameter inside URL.
>
> The interface IRequestTargetMountsInfo contains one method which is
> not referenced anywhere in Wicket (maybe in wicketstuff?)
Probably a left over from prior refactoring.
>
> It seems that the concept of handlers for coding URL's like   is
> great but I wish it was used at the top level and not just for
> mounted pages.

Well, nothing should prevent you from writing your own strategy and in
that strategy you can handle the mounted page as you wish. Just keep
in mind there are many kinds of URLs, and your strategy has to support
those.

Anyway, we are aware that the URL coding/decoding is far from perfect
and some parts are rather cumbersome. So it should be subject of a
major refactor in the next release.

-Matej

>
> What is bookmarkablePageClass doing in RequestParameters?  This seems
> out of place considering it is passed in as an argument to
> IRequestTargetUrlCodingStrategy which has the responsibility of
> choosing and creating the type of target.
Again, URL coding strategy is only for mounted pages. There are
bookmarkable URLS even without mounted pages, and that is handled by
WebRequestCodingStrategy.
>
> Maybe a good approach would be to iterate through all registered
> handlers for each request until one can handle it.  The default
> handling done in WebRequestCodingStrategy could simply be the last
> handler in the chain.  Resources and mounts could be first by default
> and users (like me) could add their own handlers.
>
> Anyway... just some thoughts while I am knee deep in the internals of
> this area.
>
> John.
>
> On 9 Oct 2007, at 01:24, Matej Knopp wrote:
>
> > IIRC WebRequestCodingStrategy is used for non-mounted pages only and
> > it delegates the encoding/decoding for mounted pages to
> > IRequestTargetUrlCodingStrategy.
> >
> > -Matej
> >
> > On 10/9/07, John Patterson <jd...@gmail.com> wrote:
> >> Hi,
> >>
> >> I want to build a custom url encoder fro bookmarkable pages and have
> >> been looking at BookmarkablePageRequestTargetUrlCodingStrategy.  Can
> >> someone quickly contrast the responsibilities of
> >> IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.  From a
> >> quick look it seems like they duplicate some of the encoding/decoding
> >> functionality.
> >>
> >> If I want to change the way URL's are translated for every
> >> bookmarkable page (including which page to create) should I override
> >> WebRequestCodingStrategy.encode()/decode()?
> >>
> >> Cheers,
> >>
> >> John
> >>
> >> ---------------------------------------------------------------------
> >> 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
> >
>
>

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


Re: Custom URL strategy

Posted by John Patterson <jd...@gmail.com>.
Hi,

As I am figuring out how to create my own IRequestCodingStrategy I  
have come across a few things which seem be suspicious IMHO.  I could  
be wrong with all of them but I thought I should bring them up...

These are all in WebRequestCodingStrategy

This code...

	public final RequestParameters decode(final Request request)
	{
			parameters.setPageMapName 
(WebRequestCodingStrategy.decodePageMapName(request
				.getParameter(PAGEMAP)));
		 }

	
	... calls RequestParameters ...

	public void setPageMapName(String pageMapName)
	{
		// this should be done in coding strategies, but its here as a
		// precaution
		this.pageMapName = WebRequestCodingStrategy.decodePageMapName 
(pageMapName);
	}

seems to decode the name twice.  It also seems to be getting set  
again here ...



	public static void addInterfaceParameters(final String  
interfaceParameter,
			final RequestParameters parameters)
	{
		...

		// Set pagemap name
		final String pageMapName = pathComponents[0];
		parameters.setPageMapName(pageMapName.length() == 0 ?  
PageMap.DEFAULT_NAME : pageMapName);

		...
	}

This method seems to have old Javadoc stating that

	/**
	 * Adds bookmarkable page related parameters (page alias and  
optionally page parameters). Any
	 * bookmarkable page alias mount will override this method; hence if  
a mount is found, this
	 * method will not be called.
	protected void addBookmarkablePageParameters(final Request request,

but it doesn't seem to do this any more and I think it is called  
_before_ mounts are tried

The interface IRequestTargetMountsInfo contains one method which is  
not referenced anywhere in Wicket (maybe in wicketstuff?)

It seems that the concept of handlers for coding URL's like   is  
great but I wish it was used at the top level and not just for  
mounted pages.

What is bookmarkablePageClass doing in RequestParameters?  This seems  
out of place considering it is passed in as an argument to  
IRequestTargetUrlCodingStrategy which has the responsibility of  
choosing and creating the type of target.

Maybe a good approach would be to iterate through all registered  
handlers for each request until one can handle it.  The default  
handling done in WebRequestCodingStrategy could simply be the last  
handler in the chain.  Resources and mounts could be first by default  
and users (like me) could add their own handlers.

Anyway... just some thoughts while I am knee deep in the internals of  
this area.

John.

On 9 Oct 2007, at 01:24, Matej Knopp wrote:

> IIRC WebRequestCodingStrategy is used for non-mounted pages only and
> it delegates the encoding/decoding for mounted pages to
> IRequestTargetUrlCodingStrategy.
>
> -Matej
>
> On 10/9/07, John Patterson <jd...@gmail.com> wrote:
>> Hi,
>>
>> I want to build a custom url encoder fro bookmarkable pages and have
>> been looking at BookmarkablePageRequestTargetUrlCodingStrategy.  Can
>> someone quickly contrast the responsibilities of
>> IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.  From a
>> quick look it seems like they duplicate some of the encoding/decoding
>> functionality.
>>
>> If I want to change the way URL's are translated for every
>> bookmarkable page (including which page to create) should I override
>> WebRequestCodingStrategy.encode()/decode()?
>>
>> Cheers,
>>
>> John
>>
>> ---------------------------------------------------------------------
>> 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: Custom URL strategy

Posted by John Patterson <jd...@gmail.com>.
Thanks Matej, I went ahead and built a IRequestCodingStrategy that  
delegates the standard WebRequestCodingStrategy because I want my  
strategy to be used for every Bookmarkable page and not just ones  
that I mount.  In fact my strategy needs to decide which Page is to  
be used _without_ using the concept of a mount path (i.e. /mount/my/ 
page/here/ -> MyPage.class)

But I discovered that WicketFilter.isWicketRequest(String) assumes  
that if a request path does not start with /resource/ or the empty  
path (for home pages) then it MUST be a mount or it is not handled.

So I am looking into re-implementing my strategy as a  
IRequestTargetUrlCodingStrategy but have come across another  
conceptual limitation.  When I first looked at implementing this  
interface it looked to do what I wanted but the method getMountPath()
made me suspicious.  Because my scheme would not mount a page at a  
particular path - it mounts all my pages to a completely custom scheme.

And I can see that WebRequestCodingStrategy does indeed make sure  
that pages are mounted to a particular path (not an empty path).  But  
I think I can get the behaviour I want by subclassing  
WebRequestCodingStrategy to not use a MountsMap for the path matching
and putting the encoding logic in a IRequestTargetUrlCodingStrategy.

I do get the felling that this could all be simplified somehow!

Cheers,

John

On 9 Oct 2007, at 01:24, Matej Knopp wrote:

> IIRC WebRequestCodingStrategy is used for non-mounted pages only and
> it delegates the encoding/decoding for mounted pages to
> IRequestTargetUrlCodingStrategy.
>
> -Matej
>
> On 10/9/07, John Patterson <jd...@gmail.com> wrote:
>> Hi,
>>
>> I want to build a custom url encoder fro bookmarkable pages and have
>> been looking at BookmarkablePageRequestTargetUrlCodingStrategy.  Can
>> someone quickly contrast the responsibilities of
>> IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.  From a
>> quick look it seems like they duplicate some of the encoding/decoding
>> functionality.
>>
>> If I want to change the way URL's are translated for every
>> bookmarkable page (including which page to create) should I override
>> WebRequestCodingStrategy.encode()/decode()?
>>
>> Cheers,
>>
>> John
>>
>> ---------------------------------------------------------------------
>> 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: Custom URL strategy

Posted by Matej Knopp <ma...@gmail.com>.
IIRC WebRequestCodingStrategy is used for non-mounted pages only and
it delegates the encoding/decoding for mounted pages to
IRequestTargetUrlCodingStrategy.

-Matej

On 10/9/07, John Patterson <jd...@gmail.com> wrote:
> Hi,
>
> I want to build a custom url encoder fro bookmarkable pages and have
> been looking at BookmarkablePageRequestTargetUrlCodingStrategy.  Can
> someone quickly contrast the responsibilities of
> IRequestTargetUrlCodingStrategy and WebRequestCodingStrategy.  From a
> quick look it seems like they duplicate some of the encoding/decoding
> functionality.
>
> If I want to change the way URL's are translated for every
> bookmarkable page (including which page to create) should I override
> WebRequestCodingStrategy.encode()/decode()?
>
> Cheers,
>
> John
>
> ---------------------------------------------------------------------
> 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