开发者

How to control submit url action in Wicket form?

I have a wicket web application with Page mounted to bookmarkable a开发者_C百科lias. The page contains a form object with submit action.

The problem is that though the form belongs to the page the action url doesn't contain page alias, but rather created in cryptic form of wicket action. Is there a way to adjust that behavior, so link will be like page_alias/submit ?

...
setRenderStrategy(IRequestCycleSettings.ONE_PASS_RENDER);
mountBookmarkablePage("/resetpwd", ResetPasswordPage.class); 
...
public ResetPasswordPage(final String id, final PageParameters parameters) {
    final Form form = new StatelessForm();
    form.add(new Button("submit") { 
     public void onSubmit() {
         ...
        });
 add(form);


If you subclass StatelessForm instead of Form, this will take you part of the way. Rather than having something like

action="myapp/?wicket:interface=:1:eventEditor::IFormSubmitListener::"

with the page containing the form mounted at a bookmarkable URL, you'll get something like, for example,

action="myapp/mount/path/some/params/?wicket:interface=:0:eventEditor::IFormSubmitListener::"

This uses a MixedParamUrlCodingStrategy for the mount in WebApplication.init()

You can then override encodeUrlInHiddenFields() to return true, which will give you a clean URL in the action attribute.

However, all this doesn't really change the way Wicket works with forms, i. e., you still have some Wicket-specific state data in the client's markup. The reason why this is so hard, I believe, is that Wicket is meant to help you build a web app that has state. I noticed that Wicket does a lot of stuff (like comparing submitted form values with what the model's getters return before the setters are called) behind the scenes, that I know too little about to be comfortable when just cutting it out.

You can use Wicket to provide RESTful web services, though, as outlined in this blog post. There's also a project on Google code called wicket-rest that expands on this idea. Note that this seems to work as simple as it does because it just never uses the whole component based UI building stuff.

The guy who wrote this post had a different problem, but it helped me understand Wicket forms a little better anyway.


you can hide a lot of the request mumbo jumbo by using a HybridUrlCodingStrategy like so:

mount(new HybridUrlCodingStrategy("/resetpwd", ResetPasswordPage.class));

Then when the click submit, assuming you don't redirect to a new page, the url would change from

mysite.com/DocRoot/resetpwd

to

mysite.com/DocRoot/resetpwd.1

or if you really want it to be mysite.com/DocRoot/resetpwd/submit you could create a new bookmarkable page, say ResetPasswordResult.class, set your response page to that and mount it at "/resetpwd/submit"

You might look at other encoding strategies to see if their is another that suits you better: http://cwiki.apache.org/WICKET/url-coding-strategies.html


You can take a look at http://day-to-day-stuff.blogspot.com/2008/10/wicket-extreme-consistent-urls.html and try to adapt that for Forms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜