[JAVA] Do not issue parameters to POST request and URL from Form with Wicket

Hide POST request and URL parameters from Form in Wicket

Version Wicket 7.3

** Background **

By default, when onSubmit () is executed on the form component, the parameter value is displayed in the URL.

https://mysite.com/;jsessionid=B85EE5CB0349CCA2FE37AF76AB5C30C1?wicket:bookmarkablePage=:com.mycompany.cheese.CheeseMain&Title=Havarti&group=cheeseName

trial and error

It seems that PageParametersEncoder is used by default IPageParametersEncoder: Wicket Reference

Create IPageParametersEncoder with no parameters

NoParamsPageParametersEncoder.java


public class NoParamsPageParametersEncoder extends PageParametersEncoder {
  
	public NoParamsPageParametersEncoder() {
		super();
	}

	@Override
	public Url encodePageParameters(final PageParameters pageParameters) {
		Url url = new Url();
		//Return URL as is
		return url;
	}
}

It seems that you can specify this at the time of mounting

WicketApplication.java


mount(new MountedMapper("/NextPage", NextPage.class, new NoParamsPageParametersEncoder()));

And pass it with parameters from the form

PrevPage.java


StatelessForm<PrevPage> inputForm = new StatelessForm<PrevPage>("inputForm") {

	@Override
	protected void onSubmit() {
		PageParameters newParams = new PageParameters();
		newParams.set("USER", "user_id");
		newParams.set("PASSWD", "password");
		setResponsePage(new NextPage(newParams));
	}
};

By the way, it was possible with both Form and StatelessForm.

There are few Wicket related documents ...

Recommended Posts

Do not issue parameters to POST request and URL from Form with Wicket
What to do if the JSONHint annotation does not work with lombok and JSONIC
Do not use floats and doubles to calculate decimal numbers