The Forms service can calculate the values
that a user enters into a form and display the results. To calculate
form data, you must perform two tasks. First, you create a form
design script that calculates form data. A form design supports
three types of scripts. One script type runs on the client, another
runs on the server, and the third type runs on both the server and
the client. The script type discussed in this topic runs on the
server. Server-side calculations are supported for HTML, PDF, and
form Guide (deprecated) transformations.
As part of the form design process, you can make use of calculations
and scripts to provide a richer user experience. Calculations and
scripts can be added to most form fields and objects. You must create
a form design script to perform calculation operations on data that
a user enters into an interactive form.
The user enters values into the form and clicks the Calculate
button to view the results. The following process describes an example
application that enables a user to calculate data:
The user accesses an HTML page named StartLoan.html that acts
as the web application’s start page. This page invokes a Java Servlet named GetLoanForm.
The GetLoanForm servlet renders a loan form.
This form contains a script, interactive fields, a calculate button,
and a submit button.
The user enters values into the form’s fields and clicks
the Calculate button. The form is sent to the CalculateData Java Servlet
where the script is executed. The form is sent back to the user
with the calculation results displayed in the form.
The user continues entering and calculating values until
a satisfactory result is displayed. When satisfied, the user clicks
the Submit button to process the form. The form is sent to another
Java Servlet named ProcessForm that is responsible
for retrieving submitted data. (See Handling Submitted Forms.)
The following diagram shows the application’s logic flow.
The following table describes the steps in this diagram.
Step
|
Description
|
1
|
The GetLoanForm Java Servlet
is invoked from the HTML start page.
|
2
|
The GetLoanForm Java Servlet
uses the Forms service Client API to render the loan form to the client
web browser. The difference between rendering a form that contains
a script configured to run on the server and rendering a form that
does not contain a script is that you must specify the target location
used to execute the script. If a target location is not specified,
a script that is configured to run on the server is not executed.
For example, consider the application introduced in this section.
The CalculateData Java Servlet is the target location
where the script is executed.
|
3
|
The user enters data into interactive fields
and clicks the Calculate button. The form is sent to the CalculateData Java
Servlet, where the script is executed.
|
4
|
The form is rendered back to the web browser
with the calculation results displayed in the form.
|
5
|
The user clicks the Submit button when the
values are satisfactory. The form is sent to another Java Servlet
named ProcessForm.
|
Typically, a form that is submitted as PDF content contains scripts
that are executed on the client. However, server-side calculations
can also be executed. A Submit button cannot be used to calculate
scripts. In this situation, calculations are not executed because
the Forms service considers the interaction to be complete.
To illustrate the usage of a form design script, this section
examines a simple interactive form that contains a script that is
configured to run on the server. The following diagram shows a form
design containing a script that adds values that a user enters into
the first two fields and displays the result in the third field.
フルサイズのグラフィックを表示- A.
- A field named NumericField1
- B.
- A field named NumericField2
- C.
- A field named NumericField3
The syntax of the script located in this form design is as follows:
NumericField3 = NumericField2 + NumericField1
In this form design, the Calculate button is a command button,
and the script is located in this button’s Click event.
When a user enters values into the first two fields (NumericField1
and NumericField2) and clicks the Calculate button, the form is
sent to the Forms service, where the script is executed. The Forms
service renders the form back to the client device with the results
of the calculation displayed in the NumericField3 field.