Application - posting inicial instance

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Application - posting inicial instance

Henrique Barros
Hello,

I'm a little bit lost. I'm working on an web application that uses orbeon XForms. A user creates a form in FormBuilder then with that code I put the form (form.xhtml) in resources/forms/App/Form/form folder and then I can access it via the URL /fr/App/Form/new.

I can send the inicial instance of the form via forwarding from a servlet to /fr/App/Form/new.

When the form is filled I configured the workflow-send button to send the xml of the form to another Servlet. But when I click it, the browser send the data to xforms-server. Then xforms-server responds to the browser with some other data and then the browser send the form encoded to /fr/App/Form/new again so That it can be forwarded to my Servlet defined in the properties, but instead, that encoded XML is going back to the inicial Servlet via post.

A workaround that I made for that was forwarding that encoded form to where it came so that it continues the workflo-send and the it goes back to the Servet in the properties. I used this code for that:

@Override
        protected void doPost(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
                if (APPLICATION_URLENCODED.equals(request.getContentType())) {
                       
                        RequestDispatcher rd = request.getRequestDispatcher("");
                        rd.forward(request, response);
                        return;

                }
        }

Then the workflow proceed and the XML is generated and sent to the goal Servlet.

It works like that but I don't really know how and this workaround obligates having that code instead of the workflow working without any intervention.

The questions are:
How can I do this process better?
Am I doing something wrong?
Do I have to use a page-workflow or something like that?
I could figure that the forms made in FormBuilder don't work inside the apps folder with a page-workflow.
I think I can put the form in the Http Session and do a redirect from Servlet to /fr/App/Form/new and then it loads the inicial instance of the form. Is that possible?

Thanks,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Alessandro  Vernet
Administrator
Hi Henry,

On Tue, Oct 16, 2012 at 10:22 AM, Henrique Barros
<[hidden email]> wrote:
> When the form is filled I configured the workflow-send button to send the
> xml of the form to another Servlet. But when I click it, the browser send
> the data to xforms-server. Then xforms-server responds to the browser with
> some other data and then the browser send the form encoded to
> /fr/App/Form/new again.

This is what is expected to happen. The first request is an Ajax
request, and in the response the server tells the JavaScript code it
needs to do a POST, part of an <xf:submission replace="all"/>. The
POST is always done to the same page. It cannot be done to the target
page, which in this case you configured with the
oxf.fr.detail.send.success.uri.*.* property, because browsers don't
know how to do POST of XML data to a target page (other than in the
context of an Ajax request). So instead a form POST is done to Orbeon
Forms, which does the "real" POST you're interested in to your app,
and returns the result to the browser, acting as a sort of proxy.

Now, if things behaved as described above, I image you wouldn't have a
problem, right? So knowing the the POST done after hitting the
workflow-send button is expected to go to the same page, what was the
problem you were observing?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Henrique Barros
This post was updated on .
Hello,

Yes, I undestand that's what expected to happen after click the send button. But the problem is: as I do a forward from my Servlet to /fr/App/Form/new the link in the browser is not the same anymore, it is like "MyServlet....." and because of that, when the ajax call is triggered instead of sending the ajax data to /fr/App/Form/new it goes to my servlet, that's why I had route the data again to /fr/App/Form/new so it continues with the workflow and finally send the xml to the TargetServlet defined in the properties file. Is there a workaround diferent/better than mine? Or is there some way to pass a URL by parameter that tells java script to send data calls to /fr/App/Form/new?
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Alessandro  Vernet
Administrator
Hi Henrique,

Shouldn't it be the other way around? I.e. after you hit send, the URL is still /fr/App/Form/new, but the HTML was served by MyServlet (the HTTP request to MyServlet being proxied by the XForms engine).

At that point, if your page was making Ajax requests, I would understand they could get to the wrong place. But then if in your MyServlet you redirect users to another form, say /fr/App/Form2/new, you can just do this with a redirect (client-side), so the URL in the browser changes, can't you? Or am I not understanding this properly?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Henrique Barros
Hi Alex,

Thanks for the answer!
I guess I can do redirect (client-side), so the URL in the browser changes, but I don't know how, I.e. Instead of doing an inicial forward from MyServlet to the form, I could do a redirect with posted instance so that the URL in the browser changes. Is that what you're saying?
If it is, I tried, but I don't know how can I use redirect with post parameters in Servlets, I think it is only possible in browser. In Servlet I can only use redirect with attributes via get method not with post, and I can do a forward.
And yes the ajax is going to MyServlet and then I redirect the code posted back to the form so it then can process that code and send the XML via post method to the TargetServlet.
Henrique
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Alessandro  Vernet
Administrator
Hi Henrique,

Let's make sure we're on the same page:

1. User is on /fr/your-app/your-form/new, and clicks Submit, browser does a POST to /fr/your-app/your-form/new ("POST to itself").
2. Orbeon Forms handles the POST does a POST from the server to MyServlet (aka "forward" or "server-side redirect").
3. MyServlet gets the instance, and the HTML it responds to gets "proxied" to the browser, which is still on /fr/your-app/your-form/new.
4. What happens next in your case? Users click on that page, and it loads another form served by Form Runner? Or something else?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Henrique Barros
Hi Alex,

Correction:
1. User is on /fr/your-app/your-form/new, and clicks Submit, browser does a POST to /fr/your-app/your-form/new ("POST to itself"). - Yes!
2. Orbeon Forms handles the POST does a POST from the server to MyServlet (aka "forward" or "server-side redirect"). - No - Orbeon Forms handles the POST and does a POST back to browser and next the browser does a redirect or forward to the URL in the browser - MyServlet.
3. MyServlet gets the instance, and the HTML it responds to gets "proxied" to the browser, which is still on /fr/your-app/your-form/new. - No - MyServlet gets some code like - $uuid=... and then forward it back to /fr/your-app/your-form/new.
4. What happens next in your case? Users click on that page, and it loads another form served by Form Runner? Or something else?  - After 3. Orbeon forms handles the $uuid...... code (very long code) and does a POST to the ServletReceive with the XML instance. ServletReceive is declared in the properties as the target page after a workflow-send-success.

The ajax post on 2. should be made to /fr/your-app/your-form/new and not to URL in the browser (MyServlet).

Henrique
Reply | Threaded
Open this post in threaded view
|

Re: Application - posting inicial instance

Alessandro  Vernet
Administrator
Hi Henrique,

Hang on: at step 3, here, when I use the workflow-send button, after the user clicked on the "Send" button and respond came back, in the browser, I still have whatever URL was there before (e.g. /fr/your-app/your-form/new), but with the content returned by the service. Do you see something different? Or am I misunderstanding you?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet