Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Submit form with response in new browser window

Avatar

Level 6

Is it possible to set up a submit button so that it pops up the response in a separate browser window?  With an HTML form, I can do it using target="_blank", but not aware of any such option on a LiveCycle submit button. 

If it can't be done, maybe there's another way to do what I need.  Users complete the data-entry PDF form and submit the data to a servlet, which returns another (different) PDF.  My user may look at this PDF, see a problem, and want to return to the data-entry form to change what he's entered before regenerating the output.  However, by this point my original data-entry PDF is gone.  I am not using LiveCycle on the server.  Any ideas?

1 Accepted Solution

Avatar

Correct answer by
Level 6

Many thanks for your help on this Paul.  I decided to go with the hostContainer approach despite my reservations.  Here's a simplified version of my servlet.  This version simply parrots back the XML in a separate browser window.  I hope this helps someone.

package ca.jlangdon.sampleservlets;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AnnuityFF extends HttpServlet {

        static final long serialVersionUID = 1L;

        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
                response.setContentType("text/html");
                java.io.PrintWriter out = response.getWriter();
                out.println("<html><head>");
                out.println("<title>Fulfillment Generator</title>");
                out.println("<style>body { margin: 0px; overflow:hidden }</style>");
                out.println("<script type='text/javascript'>");
                out.println("var int=self.setInterval('setUp()',1000);");
                out.println("function setUp() {");
                out.println("try {");
                out.println("var oPDF = document.getElementById('oPDF');");
                out.println("oPDF.messageHandler = {};");
                out.println("oPDF.messageHandler.onMessage = onMessageFromPdf;");
                out.println("int=window.clearInterval(int)");
                out.println("} catch(e) { } }");
                out.println("function onMessageFromPdf(oStrings) { document.getElementById('myTextArea').value = oStrings[0];");
                out.println("document.forms['myForm'].submit(); }");
                out.println("</script></head>");
                out.println("<body scroll='no'>");
                out.println("<div id='myFrame' style='background-color:transparent;border:0px'>");
                out.println("<object id='oPDF' height='100%' width='100%' data='FulfillmentGenerator.pdf'></object></div>");
                out.println("<form id='myForm' method='post' action='.' target='_blank'>");
                out.println("<textarea id='myTextArea' name='myTextArea'></textarea>");
                out.println("</form></body></html>");
        }


        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
                try {
                        String strExtract = request.getParameter("myTextArea");
                        response.setContentType("text/xml");
                        PrintWriter out = response.getWriter();
                        out.println(strExtract);
                }
                catch (Exception e) {
                }
        }
}

My form is called FulfillmentGenerator, and it's stored in the root of the web app.  On it there's a button with this javascript on the click event:

var oDoc = event.target;

var strData = xfa.datasets.data.resolveNode("AnnuityFulfillmentPackage").saveXML("pretty");

var strings = [strData];

try {

oDoc.hostContainer.postMessage(strings);

}

catch (ex) {

xfa.host.messageBox("Error while posting a message to the container: " + ex);

}

View solution in original post

6 Replies

Avatar

Former Community Member

What if you returned a PDF as your response ....then the response PDF woudl open in the same session and the user could flip between opened PDFs as required.

Paul

Avatar

Level 6

Hi Paul,

Thanks for the idea, but I'm not sure how that would work.  I am, in fact, returning a PDF, but it's a static document.  How would the user flip back to the completed PDF data-entry form?  The browser back button won't do it.

Having slept on it, I have thought of two approaches:

1) Submit XDP including the PDF itself.  The form can have save rights applied using Acrobat (there are way fewer than 500 users of the form), so I think that's possible even with the free Reader.  The completed PDF will be base-64 encoded in the submitted data (right?).  On the server I can decode the completed PDF and serve it back to the user if needed.  When I return the static PDF, I do so inside a DIV or iFrame or object tag or something along those lines with a link back to the completed PDF in a separate frame.

2) I embed my LiveCycle data-entry form in an object tag inside a wrapper HTML page.  That HTML page contains a hidden HTML form.  I use the hostContainer object in my form to invoke javascript on the wrapper form.  I pass the XML data from the PDF form to the wrapper using hostContainer messaging and submit the HTML form programatically with target="_blank".  This allows me to get my response in a separate browser window.

The first option requires me to hang on to the completed PDF on the server so that I can serve it back to the user if needed.  I like the second option, but I'm wary of using hostContainer.  I've played with it in the past and run into problems with different browsers and/or user security settings.  I don't remember the details, but it was problematic.  That said, I was using it to integrate with a Flex applet, so there were more variables in the mix.  Straight PDF to wrapper javascript should be more reliable.  I'd appreciate your thoughts.  Thanks.

Jared

Avatar

Former Community Member

What if you submitted the PDF in a web service call ....then you coudl return a string that thanks them for the submission and you can have logic in your form that woudl display the returned message while still inside of your original form?

Paul

Avatar

Level 6

That's a good idea.  The web service could even return a unique identifier and call app.launchURL with a URL that includes the identifier.  That can pop a separate browser window with the content that I want to serve up.  Hmmm.  Can Reader call web services using usage rights enabled by Acrobat?  My client doesn't have LC Reader Extensions.

Avatar

Former Community Member

Nope …you would need LC Reader Extensions

Paul

Avatar

Correct answer by
Level 6

Many thanks for your help on this Paul.  I decided to go with the hostContainer approach despite my reservations.  Here's a simplified version of my servlet.  This version simply parrots back the XML in a separate browser window.  I hope this helps someone.

package ca.jlangdon.sampleservlets;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AnnuityFF extends HttpServlet {

        static final long serialVersionUID = 1L;

        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
                response.setContentType("text/html");
                java.io.PrintWriter out = response.getWriter();
                out.println("<html><head>");
                out.println("<title>Fulfillment Generator</title>");
                out.println("<style>body { margin: 0px; overflow:hidden }</style>");
                out.println("<script type='text/javascript'>");
                out.println("var int=self.setInterval('setUp()',1000);");
                out.println("function setUp() {");
                out.println("try {");
                out.println("var oPDF = document.getElementById('oPDF');");
                out.println("oPDF.messageHandler = {};");
                out.println("oPDF.messageHandler.onMessage = onMessageFromPdf;");
                out.println("int=window.clearInterval(int)");
                out.println("} catch(e) { } }");
                out.println("function onMessageFromPdf(oStrings) { document.getElementById('myTextArea').value = oStrings[0];");
                out.println("document.forms['myForm'].submit(); }");
                out.println("</script></head>");
                out.println("<body scroll='no'>");
                out.println("<div id='myFrame' style='background-color:transparent;border:0px'>");
                out.println("<object id='oPDF' height='100%' width='100%' data='FulfillmentGenerator.pdf'></object></div>");
                out.println("<form id='myForm' method='post' action='.' target='_blank'>");
                out.println("<textarea id='myTextArea' name='myTextArea'></textarea>");
                out.println("</form></body></html>");
        }


        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
                try {
                        String strExtract = request.getParameter("myTextArea");
                        response.setContentType("text/xml");
                        PrintWriter out = response.getWriter();
                        out.println(strExtract);
                }
                catch (Exception e) {
                }
        }
}

My form is called FulfillmentGenerator, and it's stored in the root of the web app.  On it there's a button with this javascript on the click event:

var oDoc = event.target;

var strData = xfa.datasets.data.resolveNode("AnnuityFulfillmentPackage").saveXML("pretty");

var strings = [strData];

try {

oDoc.hostContainer.postMessage(strings);

}

catch (ex) {

xfa.host.messageBox("Error while posting a message to the container: " + ex);

}