How to control the flow of a url action in a Wicket form?

I have a wicket web application with a page attached to a bookmark alias. The page contains a form object with a submit action.

The problem is that although the form belongs to the page, the action URL does not contain the page alias, but rather is created in a critical gate form. Is there a way to customize this behavior so that the link will look 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); 
+4
source share
3 answers

If you subclass StatelessForm instead of Form , this will take you part of the path. Instead of having something like

action = "MyApp / Gate: interface =: 1: eventEditor :: IFormSubmitListener ::"

with the page containing the form mounted at the URL available for bookmarking, you will get something like, for example,

action = "MyApp / mount / path / some / Titles / Wicket: interface =: 0: eventEditor :: IFormSubmitListener ::"

It uses MixedParamUrlCodingStrategy to 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 does not change the way Wicket works with forms, i.e. for example, you still have some Wicket-specific status data in client markup. I think this is so difficult, I suppose, is that Wicket is designed to help you create a status-based web application. I noticed that Wicket does a lot of things (for example, comparing the submitted form values ​​with what is returned by the model before the setters are called) backstage that I know too little to be convenient when I just cut it out.

You can use Wicket to provide RESTful web services, though, as stated in this blog post . There is also a project in Google code called wicket-rest that expands on this idea. Note that this works as simple as that because it never uses the entire component to create a component-based user interface.

The guy who wrote this post had another problem, but it helped me understand that the Wicket form is a little better anyway.

+3
source

you can hide many mumbo jumbo requests using HybridUrlCodingStrategy, for example:

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

Then, when the "Submit" button, if you are not redirected to a new page, the URL will 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 bookmark page, for example ResetPasswordResult.class, set your own answer page for it and set it on the page "/ resetpwd / submit"

You can look at other coding strategies to see if they suit another, which suits you: http://cwiki.apache.org/WICKET/url-coding-strategies.html

+1
source
0
source

All Articles