Summary of steps

To calculate form data, perform the following tasks:

  1. Include project files.
  2. Create a Forms Client API object.
  3. Retrieve a form containing a calculation script.
  4. Write the form data stream back to the client web browser

Include project files

Include necessary files into your development project. If you are creating a client application using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.

Create a Forms Client API object

Before you can programmatically perform a Forms service Client API operation, you must create a Forms service client. If you are using the Java API, create a FormsServiceClient object. If you are using the Forms web service API, create a FormsServiceService object.

Retrieve a form containing a calculation script

You use the Forms service Client API to create application logic that handles a form that contains a script configured to run on the server. The process is similar to handling a submitted form. (See Handling Submitted Forms.)

Verify that the processing state associated with the submitted form is 1 (Calculate), which means that the Forms service is performing a calculation operation on the form data and the results must be written back to the user. In this situation, a script configured to run on the server is automatically executed.

Write the form data stream back to the client web browser

After you verify the processing state associated with a submitted form is 1, you must write the results back to the client web browser. When the form is displayed, the calculated value will appear in the appropriate field(s).

See also

Including AEM Forms Java library files

Setting connection properties

Forms Service API Quick Starts

Rendering Interactive PDF Forms

Creating Web Applications that Renders Forms

Calculate form data using the Java API

Calculate form data by using the Forms API (Java):

  1. Include project files

    Include client JAR files, such as adobe-forms-client.jar in your Java project’s class path.

  2. Create a Forms Client API object

    • Create a ServiceClientFactory object that contains connection properties.
    • Create an FormsServiceClient object by using its constructor and passing the ServiceClientFactory object.
  3. Retrieve a form containing a calculation script

    • To retrieve form data that contains a calculation script, create a com.adobe.idp.Document object by using its constructor and invoking the javax.servlet.http.HttpServletResponse object’s getInputStream method from within the constructor.

    • Invoke the FormsServiceClient object’s processFormSubmission method and pass the following values:

      • The com.adobe.idp.Document object that contains the form data.
      • A string value that specifies environment variables including all relevant HTTP headers. You must specify the content type to handle by specifying one or more values for the CONTENT_TYPE environment variable. For example, to handle XML and PDF data, specify the following string value for this parameter: CONTENT_TYPE=application/xml&CONTENT_TYPE=application/pdf
      • A string value that specifies the HTTP_USER_AGENT header value; for example, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322).
      • A RenderOptionsSpec object that stores run-time options.

      The processFormSubmission method returns a FormsResult object containing the results of the form submission.

    • Verify that the processing state associated with a submitted form is 1 by invoking the FormsResult object’s getAction method. If this method returns the value 1, the calculation was performed and the data can be written back to the client web browser.

  4. Write the form data stream back to the client web browser

    • Create a javax.servlet.ServletOutputStream object used to send a form data stream to the client web browser.
    • Create a com.adobe.idp.Document object by invoking the FormsResult object ‘s getOutputContent method.
    • Create a java.io.InputStream object by invoking the com.adobe.idp.Document object’s getInputStream method.
    • Create a byte array and populate it with the form data stream by invoking the InputStream object’s read method and passing the byte array as an argument.
    • Invoke the javax.servlet.ServletOutputStream object’s write method to send the form data stream to the client web browser. Pass the byte array to the write method.