One of the shortcomings of Wicket at this moment (versions 1.2 and 1.3) is non-Human-readable URL. In this article there are ways to avid that which are the results of the research Enterra made. The purpose of that was to get REST-style URL.
When using the solutions described in this article it needs to consider the difference between the versions of Wicket! They are described here at: http://cwiki.apache.org/WICKET/migrate-13.html
Generally REST-style URL can be get for the pages that have been “mounted” using the method
For this in the constructor of the successor-class org.apache.wicket.protocol.http.WebApplication we do the following:
on the arguments mount() please see the documentation.
In this case the URL to pages that are located on mounted packages looks this way:
passed parameters for these pages will look like this:
http://localhost: 9090/wicket_res/app /pages/user/personal/MyProfilePage/tab/Basic
the parameter passed: tab=Basic.
Why this way is handy?
1. all pages can be mounted at the same time that are in the package specified.
2. when adding BookmarkablePageLink, linking to such page it will immediately gets the desired look.
To create a URL of this style for forms (successors of org.apache.wicket.markup.html.form.Form) is more complex since Wicket after handling the form goes to the address specified in the “action” attribute of the form’s tag in the method onComponentTag.
When searching for an extension of the form there two results of work for the form:
1. when the form is filled out with no errors and onSubmit()of the form works;
2. the form contains errors (detected by validators) and onError() of the form is triggered;
This article provides the following steps to resolution:
In the first case in the onSubmit() method of the form we make transfer to the required page:
If we set up the mounted (please see above) page the the URL will be as required.
But Wicket 1.3 on the Stateless form this setup is not working. It happens because Wicket 1.3 compared to ver 1.2 in the method of the class класса org.apache.wicket.RequestCycle
public final CharSequence urlFor(final Component component,final RequestListenerInterface listener)
watches if the form corresponds to the condition
(listener != IRedirectListener.INTERFACE && component.isStateless() && page.isBookmarkable())
and generates the URL into the action attribute of the form using BookmarkableListenerInterfaceRequestTarget.
Thus the URL looks like this:
On the issue:
“as of right now wicket will not keep a mount in the path. we have talked about doing that for a while, but just haven’t found the time. please add an rfe for 1.4 and we will look into it.”
To make the page Bookmarkable it should have the constructor YouPage(final PageParameters parameters) besides others.
To make the form considered as Stateless, in the method of this form getStatelessHint should be returned true.
In the second case, in a similar was it can be made in the onError() of the form. However, here all FeedbackMessages will be lost. But since in the ver. 1.3 these messages are stored in a session, (the construction is admissible Session.get().getFeedbackMessages().hasErrorMessageFor(component)), there of course should be a way to extract them from there and set up manually. However it has not been found
We can only hope that in further versions the developers of Wicket will add the functionality that allows solving issues of giving a URL Human-readable style.
By changing the implementation Application.newRequestCycleProcessor with appropriate strategies (implementations org.apache.wicket.request.IRequestCodingStrategy) something can be achieved.
On the issue:
“if you are really set on having that behavior, then like i said, use stateless pages and forms. if that doesnt work then of course you can plugin your own url coding strategy – but for what you want i would not imagine it would be a trivial thing to write.”
An Alternative Variant.
Use AJAX instead of forms. The Human-readable URL generation issue is removed.
This entry was posted on Monday, August 27th, 2007 at 3:26 am and is filed under Wicket.