You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by senlog80 <se...@gmail.com> on 2016/08/17 12:58:35 UTC

POST request shows the parameters in the URL of result page

I have a form on my page, which when submitted goes the next page, but all
the form's fields appear as URL parameters in the resulting page.  I want to
hide all the parameters in the url, so that I am using POST request but
still it shows the parameters in the resulting page.   

My sample code
------------------- 
HomePage.java
------------------
PageParameters pp = new PageParameters(); 
    pp.add("lastName", lastName); 
    pp.add("firstName", firstName); 
    pp.add("commonName", commonName); 
    pp.add("localeStr", localeStr); 
throw new RestartResponseException(UserDetailPage.class, pp); 

UserDetailPage 
---------------- 
        public UserDetailPage(final PageParameters parameters) { 
                String lastName = parameters.get("lastName").toString(); 
                String firstName = parameters.get("firstName").toString(); 
                String commonName = parameters.get("commonName").toString(); 
userForm = new UserForm("modifyForm", parameters); 
add(userForm);	

UserForm.java
----------------
	public UserForm(String id, PageParameters parameters) {
		super(id);
		String typeFlagValue = "COMMON";
		if (parameters != null)
		{
			this.localeStr = parameters.get("localeStr").toString();
			this.userDN = parameters.get("parentDN").toString();
			this.userName = parameters.get("commonName").toString();
			this.firstName = parameters.get("firstName").toString();
			this.lastName = parameters.get("lastName").toString();
		}

Actually, From the HomePage.java, the request parameters are passed to
UserDetailPage.java.  This UserDetailPage.java takes the reference Userform
and shows the result in the GUI.  

So, the page parameters lastName, firstName, commonName, etc.. are shown in
the URL of result page.
We are using Bookmarakable Page.

If I use the "throw new RestartResponseException(new UserDetailPage(pp));"
instead of "throw new RestartResponseException(UserDetailPage.class, pp);"
in HomePage.java then the URL hides the parameters in the URL.  But I think
this is stateful.  Is it ok??

Could you provide the suggestions.. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/POST-request-shows-the-parameters-in-the-URL-of-result-page-tp4675323.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: POST request shows the parameters in the URL of result page

Posted by senlog80 <se...@gmail.com>.
Actually, we are calling the UserDetailPage.java from HomePage.java. 
UserDetailPage.java contains the instantiation of UserForm.java which
extends the Wicket Form class.   This UserForm.java stores the post
parameters into a model object and retrieves back whenever it is needed. 

HomePage.java
------------------
public HomePage(final PageParameters parameters) {
		super(parameters);
		String lastName = getParameterValue("sn", parameters, postParams);
		String firstName = getParameterValue("givenname", parameters, postParams);
		String commonName = getParameterValue("cn", parameters, postParams);

PageParameters pp = new PageParameters();
				pp.add("lastName", lastName);
				pp.add("firstName", firstName);
				pp.add("commonName", commonName);
throw new RestartResponseException(UserDetailPage.class, pp);

}

UserDetailPage.java
-----------------------
	public UserDetailPage(final PageParameters parameters) {
		String lastName = parameters.get("lastName").toString();
		String firstName = parameters.get("firstName").toString();
		String commonName = parameters.get("commonName").toString();
		String email = parameters.get("email").toString();

		add(userForm);	
}
UserForm.java
------------------
public UserForm(String id, PageParameters parameters) {
		super(id);
		String typeFlagValue = "COMMON";
		if (parameters != null)
		{
			this.localeStr = parameters.get("localeStr").toString();
			this.userDN = parameters.get("parentDN").toString();
			this.userName = parameters.get("commonName").toString();
			this.firstName = parameters.get("firstName").toString();
			this.lastName = parameters.get("lastName").toString();
		}
User user = new User();
		CompoundPropertyModel userModel =
				new CompoundPropertyModel<User>(user);
		setDefaultModel(userModel);
....


I understood the calling procedure for html, I will try this option and
update the status.

Thanks
Senthil

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/POST-request-shows-the-parameters-in-the-URL-of-result-page-tp4675323p4675343.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: POST request shows the parameters in the URL of result page

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Sorry, but you are giving us partial information and it is hard for us to
guess what you are doing there.
It is still not clear how you use UserForm and whether you really need it.

From your previous email I understood that you want to submit a form in
HomePage and get its data in UserDetails without polluting the url with
query string parameters and still keeping your pages stateless. Is this
correct ?
It it is then remove UserForm completely and in HomePage.html use normal
HTML (i.e. no wicket:id): <form action="/user/details" method="POST"> <!--
some form elements here --> </form>
Submittting this form will send its data directly to UserDetails page (if
it is mounted at /user/details !). There you have to use
getRequest().getPostParameters() to read the submitted data, because
PageParameters is only for GET requests.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Aug 19, 2016 at 11:14 AM, senlog80 <se...@gmail.com> wrote:

> Thanks Martin..
>
> Could you provide a sample code if possible or any reference for calling
> the
> html instead of wicket Form
>
> Is it like the following statement has to be replaced from HomePage.java to
> HomePage.html
>  "throw new RestartResponseException(UserDetailPage.class, pp);" --> <form
> action="/user/details" method="POST">
>
> Actually, the class "UserForm extends Form" and it has the code for setting
> and retrieving the data in model object.  In this class only, we have
> written the code for OnSubmit() functionality for modify button.
>
> We have HomePage.java / HomePage.html and UserDetailPage.java /
> UserDetailPage.html
>
> Please let me know if there is any sample code.
>
> Thanks
> Senthil
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/POST-request-shows-the-parameters-in-the-URL-of-result-page-
> tp4675323p4675340.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: POST request shows the parameters in the URL of result page

Posted by senlog80 <se...@gmail.com>.
Thanks Martin..

Could you provide a sample code if possible or any reference for calling the
html instead of wicket Form

Is it like the following statement has to be replaced from HomePage.java to
HomePage.html
 "throw new RestartResponseException(UserDetailPage.class, pp);" --> <form
action="/user/details" method="POST">

Actually, the class "UserForm extends Form" and it has the code for setting
and retrieving the data in model object.  In this class only, we have
written the code for OnSubmit() functionality for modify button.

We have HomePage.java / HomePage.html and UserDetailPage.java /
UserDetailPage.html

Please let me know if there is any sample code.

Thanks
Senthil

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/POST-request-shows-the-parameters-in-the-URL-of-result-page-tp4675323p4675340.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: POST request shows the parameters in the URL of result page

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Wed, Aug 17, 2016 at 2:58 PM, senlog80 <se...@gmail.com> wrote:

> I have a form on my page, which when submitted goes the next page, but all
> the form's fields appear as URL parameters in the resulting page.  I want
> to
> hide all the parameters in the url, so that I am using POST request but
> still it shows the parameters in the resulting page.
>
> My sample code
> -------------------
> HomePage.java
> ------------------
> PageParameters pp = new PageParameters();
>     pp.add("lastName", lastName);
>     pp.add("firstName", firstName);
>     pp.add("commonName", commonName);
>     pp.add("localeStr", localeStr);
> throw new RestartResponseException(UserDetailPage.class, pp);
>

The form submit POST request ends here.
From now on a new GET request is issued with url like
/user/details?lastName=last&firstName=first...


>
> UserDetailPage
> ----------------
>         public UserDetailPage(final PageParameters parameters) {
>                 String lastName = parameters.get("lastName").toString();
>                 String firstName = parameters.get("firstName").toString();
>                 String commonName = parameters.get("commonName").
> toString();
> userForm = new UserForm("modifyForm", parameters);
> add(userForm);
>
> UserForm.java
> ----------------
>         public UserForm(String id, PageParameters parameters) {
>                 super(id);
>                 String typeFlagValue = "COMMON";
>                 if (parameters != null)
>                 {
>                         this.localeStr = parameters.get("localeStr").
> toString();
>                         this.userDN = parameters.get("parentDN").
> toString();
>                         this.userName = parameters.get("commonName").
> toString();
>                         this.firstName = parameters.get("firstName").
> toString();
>                         this.lastName = parameters.get("lastName").
> toString();
>                 }
>
> Actually, From the HomePage.java, the request parameters are passed to
> UserDetailPage.java.  This UserDetailPage.java takes the reference Userform
> and shows the result in the GUI.
>
> So, the page parameters lastName, firstName, commonName, etc.. are shown in
> the URL of result page.
> We are using Bookmarakable Page.
>
> If I use the "throw new RestartResponseException(new UserDetailPage(pp));"
> instead of "throw new RestartResponseException(UserDetailPage.class, pp);"
> in HomePage.java then the URL hides the parameters in the URL.  But I think
> this is stateful.  Is it ok??
>

IMO the best for your use case if to not use Wicket Form at all in HomePage.
Use a normal HTML form: <form action="/user/details" method="POST">.
This will go directly to UserDetailsPage where you can read the parameters
with getRequest().getPostParameters()


>
> Could you provide the suggestions..
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/POST-request-shows-the-parameters-in-the-
> URL-of-result-page-tp4675323.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>