How can I get post parameters?

Hi

There is an external html form at 3. party website.
They are submitting form parameters to my vaadin application by setting form action parameter to http://www.myvaadinapplication.com/someurl
They are not submitting parameters by querystring. They use post parameters.

How can I get these post parameters in my vaadin application.

Use a custom RequestHandler - see e.g.
this wiki article
. The method getParameter() on the request also returns POST parameters if I remember correctly.

Note that in your case, you’d probably want to register the handler on the VaadinService rather than a VaadinSession. To do this, you can override VaadinService.createRequestHandlers() and append your handlers to the list returned by super.createRequestHandlers(). To use your custom service, override VaadinServlet.createServletService() and copy the logic from the superclass to initialize the service correctly.

Hi,

I’ve tried that it works for querystring but not form parameters.
I prepared a sample project contains the situation. ((Sample Project) test.zip size was 40mb. So I’ve deleted target folder.)

Am I missing something?

Thanks in advance.
16438.zip (376 KB)

Hi again,

I put an html form in mytheme folder. (form.html)
When I post the form, I see post parameters correctly. But handleRequest method executes twice. Why?

When I place html form outside of the application (external form), I couldn’t get post parameters.
Is it about CORS?

Thanks

Hi, Vaadin has a two-stage initialization. The initial HTTP request initiated by the user loads a minimal bootstrap page, which in turn sends an AJAX request that initializes the UI itself (the latter request is what is passed to the UI.init method). The problem is, POST parameters are lost in this process, as there’s no easy way to just copy them from the first request to the second (unlike with GET parameters where you just need the URL).

Please refer to
ticket #13079
for more discussion and potential solutions.

Ah, true - even RequestHandlers in VaadinService require a session to have been initialized. Overriding VaadinServlet.service() is a last resort option if other solutions don’t work for you, especially if the POST does not apply to a specific UI but triggers some background processing.

Hi,

In this case the form submits to a specific url. So do you suggest any other solution except overriding VaadinServlet.service()?

I think, the cleanest solution would be to have a

Page.getCurrent().open(arg1, arg2);

that can do a post, maybe add a third parameter to add the post content. Of course, that would be a feature request but a very useful one.