P8 Eforms Java API Developer Guide
P8 Eforms Java API Developer Guide
Version 1.0
SC19-3247-00
IBM FileNet eForms for P8 Java API Developer Guide
Version 1.0
SC19-3247-00
Note
Before using this information and the product it supports, read the information in “Notices” on page 59.
Edition notices
This edition applies to version 1.0 of IBM eForms Java API Developer Guide (product number 5724-R85) and to all
subsequent releases and modifications until otherwise indicated in new editions.
© Copyright IBM Corporation 2011.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract
with IBM Corp.
FileNet eForms for P8 Java API
Developer Guide
Introduction
Use cases
The eForms Java API provides the ability to programmatically support
eForms functionality through JSP pages, servlets or standalone
desktop applications.
The packages for the eForms API are all com.filenet.eforms.api.*. So,
you need to include the following line in your java code:
import com.filenet.eforms.api.*;
Initialization
Before any calls can be invoked, the eForms API must be initialized for
the particular deployment. This is done using the Configuration
object with its single static method initialize(). This method should
only be called once; any succeeding calls to it are ignored.
Configuration.initialize(getServletContext().getRealPath("/
WEB-INF"));
A JSP page may establish the location of this folder with this
command:
Configuration.initialize(application().getRealPath("/WEB-
INF"));
Configuration Files
Name Description
This file is a deployment descriptor. It provides
web.xml configuration and deployment information for the
Web components that comprise a Web application.
eforms- This file is covered in more detail in the Integration
integration.xml section.
eforms-integration.xml
<integration>
....
<sources>
<source scheme="p8" >
com.filenet.eforms.toolkit.server.sources.P8Source
</source>
<\sources>
....
</integration>
p8:(ObjectStoreID).(ObjectID)
where the value of ObjectStoreID & ObjectID are a GUID like:
0C4F3B79-6C8A-4859-916B-93E90101CBE1
try
{
// Initialize the context with the required data.
Hashtable context = Context.initialize();
context.put("locale", request.getLocale());
context.put("timeZone", TimeZone.getDefault());
context.put("username" , "Joe Schmeg");
P8 Content Provider
If you are using P8 to support your eForms, then you will need to
implement a larger set of commands to set up the content. The
try
{
// Get the data store from the controller.
WcmDataStore dataStore = controller.getDataStore();
// Get the locale from the data store.
Locale locale = dataStore.getLocale();
// Get the session from the data store.
session = dataStore.getSession();
// Get the timezone from the client time zone utility.
TimeZone timeZone = null;
try
{
if(ClientTimeZoneUtil.isTimeZoneExplicit(dataStore))
timeZone =
ClientTimeZoneUtil.getClientTimeZone(dataStore, null);
else
timeZone =
ClientTimeZoneUtil.getBrowserTimeZone(dataStore);
}
catch (Throwable e)
{
timeZone = TimeZone.getDefault();
}
// Initialize the context with the required data.
Hashtable context = Context.initialize();
context.put("locale", locale);
context.put("session", session);
context.put("timeZone", timeZone);
// eForms java API calls would go here
...
}
finally
{
//Release the context.
context.release();
}
The following JSP page shows the initialization of the eForms and how
to use the eForms Java API to open an ITX Form Template.
Template Objects
A Template object represents a form template. Thus, you can use the
Template object to create an instance of a Form object.
Users fill out a form by entering values in the fields (cells) on the form.
The eForms API supports the following URI Schemes: file, http, https
and P8. The P8 URI scheme is supported only for the P8 eForms
platform and cannot be used for the standalone application.
You can create a Form object by calling one of the following methods
on the Form class:
package myapp;
import com.filenet.eforms.api.Configuration;
import com.filenet.eforms.api.Context;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.IO.Exception;
import java.util.Hashtable;
Configuration.initialize(getServletContext().getRealPath("/
WEB-INF"));
form.merge(data, true);
In the Sample JSP page, you can parse the Template and Data object
to create a new Form:
NOTE The eForms Java™ API does not enable you to modify the
template properties
You can also use the form variable to access these collections and the
objects they contain. For example, you call the getPage method on the
form to access the PageCollection object.
To access a specific object from a collection you can call the get or
find method on the appropriate collection object. In addition, you can
access a specific object directly using the form variable. For example,
to access a specific cell, you can call the findCell(string),
getCell(string), or getCell(number) method on the form.
The Form object also allows you to set the current cell to the first
editable cell on a particular page:
The following example calls the doSubmit to execute the submit action
configured for the Form.
You can execute the auto-increment action for a specific cell or for all
cells.
The following example increments the values in all cells that have been
configured in eForms Designer to hold an auto-incrementing value:
NOTE Exceptions are not thrown to the user indicating the failure of
any particular Auto-Increment set up on a cell. This is a design feature
as a Form can have multiple Auto-increments configured, so even if
one of them fails the others can function.
Every form contains one or more numbered pages, a work page, and a
master page. The PageCollection object for a form contains a Page
object for the work page and for each numbered page. The work page
is always the first element in the 0-based page collection.
The Page object enables you to access information about the page,
such as whether the form user can access the page or is the page tab
visible or is it printable. This object also enables you to work
specifically with the cells that appear only on that page.
This topic describes how to get information about the page properties
defined in eForms Designer and how to access cells on a specific page.
You can use the following methods on the Page object to obtain
information about the page.
Your code can access the cells that are defined for the work page or
for a specific numbered page through the CellCollection object
maintained for that page. To access the CellCollection object, call
the getCells command on the Page object.
To access a specific cell for a page, call one of the the following
methods on the Page object:
The following example finds a page from the page collection and gets
all the published cells for that particular page
Iterator it = form.getPages().iterator();
while (it.hasNext())
{
Page page = (Page) it.next();
if (page.getName() == "MyPage")
{
page.setTabVisible(true);
CellCollection cells = page.getPublishedCells();
Cell mycell = cells.getCell("test");
myCell.setValue("Just for testing");
You can create a non-template cell for a form. Like a template cell, a
non-template cell is either a field cell or a column cell. The multiplicity
of a non-template cell is determined by the createCell method you
call.
Both createCell methods add the new non-template cell to the cell
collection for the form. You get and set the value of the new non-
template cell as you would for a template cell. However, the non-
template cell does not have template-specific properties such as a
display name.
To set a value to a cell object, you need to know whether you are
working with a field cell or a column cell and whether you are using a
Value object or a string to set the cell value.
To set the value of a specific row in a column cell from a string, call
one of the following methods on the Cell object:
To set all the values in a column cell from an array of strings, call one
of the following methods on the Cell object:
You can execute the auto-increment action for a specific cell or for all
cells.
Performing a Lookup
The following example calls the doLookup to execute the lookup action
configured for a cell named lookupCell. The example then extracts the
lookup data returned by the doLookup method from any data sources,
and merges the data to the appropriate fields in the Form Template:
Iterator it = form.getCells().iterator();
while (it.hasNext())
{
Cell cell = (Cell) it.next();
if (cell.getName().equalsIgnoreCase("lookupCell"))
{
// perform lookup
cell.setValue(new Value("John Smith"));
resp = cell.doLookup();
}
}
You can use the verifySignature method on the Cell object to verify
the user's signature. This method sends a request to the signing
service to verify the user's signature.
String result;
SignatureState status =
form.findCell("Signature").verifySignature();
if (status == SignatureState.Invalid)
result = "Invalid signature.";
else if (status == SignatureState.NotSigned)
result = "Please enter a signature.";
else if (status == SignatureState.NotVerified)
result = "The signature has not been verified.";
The value type of a Value object is immutable; however, you can cast
the Value object to a Value object of a compatible type. To determine
the value type, call the getType method on the Value object.
You can create Value objects directly by calling one of the constructors
or parse methods defined on the Value object. You can create Value
objects indirectly by calling methods such as getValue on Cell objects
or findValue on Data objects.
You can create a new Value object of a given type by calling the Value
constructor. The argument you pass to the constructor determines the
value type of the new object. If you do not pass an argument to the
Value constructor, the constructor creates an empty Value object with
the ValueType property set to Null.
Examples
The following example creates a Value object of type Null, and sets the
value of the new object to true:
The following example creates a Value object of type Date, and sets
the value of the new object to 2004-06-10:
You can create a Value object of any type and use a string to set the
value. To do so, pass a string to the appropriate parse method for the
type. For example, the following call creates a new Value object of type
Boolean with the value set to true:
The Value object provides two parse methods for each value type. The
method you choose depends on the format of the string to be used to
set the value. To create a Value object from a localized string in the
general format style, call a plain parse method such as parseBoolean
or parseSignature. To create a Value object from a string in the
canonical format, call a parseCanonical method such as
parseCanonicalBoolean or parseCanonicalSignature.
You can also create a Value array object and assign any specific value
object types like boolean, string , DateDetail or TimeDetail. The
The following example creates a Value object and appends the value
to a particular field/column in the Form and the Data object.
You can cast a Value object to another Value object or to another kind
of object. Both cases require the resulting object to be of a type that is
compatible with the Value object on which the method is called.
To cast a Value object to another Value object, you call one of the as
methods on the Value object. The following example calls the
asString method to cast a Value object of type Number to a Value
object of type String:
To cast a Value object to another kind of object, you call one of the to
methods on the Value object. The following example calls the toTime
method to cast a Value object of type Time to a TimeDetail object:
You can use the eForms JavaScript API to define the choices in a
choice list. In addition, you can specify whether the form user can
enter a value not contained in the choice list.
You create a choice list by calling one of the following methods on the
form:
The following example creates a new choice list named ColorList with
three values: orange, purple, and green:
You can obtain a reference to a choice list using the form, the choice
list collection, or the cell object.
To obtain a reference to a choice list using the form, call one of the
following methods on the form:
To obtain a reference to the choice list collection for a form, call the
getChoiceLists method on the form. You can then obtain a reference
to a choice list using the choice list collection, by calling one of the
following methods on the ChoiceListCollection object:
You can associate a choice list with any template cell except for a
picture or signature cell or a cell defined as a checkbox. To do so, call
one of the setChoiceList methods on the Cell object as follows:
The following example associates the choice list ColorList with a cell
named ColorChoice:
If a choice list is already associated with a cell, the choice list specified
by the setChoiceList method supersedes the existing choice list.
However, the original choice list is not deleted from the choice list
collection. The setChoiceList method also overrides the
allowOtherValues property set for the cell.
The following example replaces the choices in the ColorList choice list
with the specified new values:
You can create a new command using the ScriptCommand object. You
can specify the javascript code that needs to be executed while
invoking this type of command.
The following example creates a simple script command that alerts the
user with a message when invoked.
renderer.getToolbarItems().add(cmdButton);
renderer.setToolbarPosition(ToolbarPosition.Top);
You can create a toolbar button with a specific name and add that
button to the toolbar collection object in order to get that button
displayed in the form. The toolbar button can be assigned a command
object so it can invoke specific operations.
The following example creates a new toolbar button that can invoke to
a Script command when rendered in a form.
renderer.getToolbarItems().add(testButton);
tblCollection.add(new ToolbarButton("TEST"));
tblCollection.add(new ToolbarSeparator("Blank");
The following example get the javascript response from a lookup and
executes the script through a Scriptcommand object
Printing a Form
You can print a form to a specific network printer, if the printername
is set to null, then the form is rendered to the default printer. You can
also set the number of copies to be printed using the PrintRenderer
object.
The following examples creates Data object using the file & P8 URI
schemes.
You can create a Data object by calling one of the following methods
on the Data class
You can pre-fill the cells on the form by merging one or more Data
objects into the Form object.
form.merge(data, true);
In the Sample JSP page, you can parse the Template and Data object to
create a new form
You can set a value to a field cell or a column cell after checking the
type of the cell. Also you can remove a specific cell from the Data
object:
data.setValues("Column1", myValueArray);
if (data.hasCell("Column2"))
data.remove("Column2");
You can also use the methods on the Forms, Page, Cell, and
ChoiceList object to customize the behavior of the electronic form
itself.
• getBuiltInCommands
• getBuiltInToolbarItems
• getHeight
• getOfflineDom
• getWidth
• render
Adding commands
The following example adds the built-in "pdf" command and a custom
script command called "helloWorld" to the command collection.
The following example adds the built-in "pdf" toolbar button and the
custom toolbar command to the toolbar item collection.
Adding a Notification
Additional Settings.
//Hide PageTabs
renderer.setPageTabsVisible(false);
Once the HtmlFormRenderer object has been created and all its
properties are modified, then the form can be rendered to the web
browser using the following command:
renderer.setForm(form);
renderer.getCommands().add(renderer.getBuiltInCommands());
renderer.getToolbarItems().add(renderer.getBuiltInToolbarIt
ems());
renderer.setToolbarPosition(ToolbarPosition.Top);
renderer.render(request, response);
import com.filenet.eforms.api.Configuration;
import com.filenet.eforms.api.Context;
import com.filenet.eforms.api.HtmlFormRenderer;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Hashtable;
Configuration.initialize(getServletContext().getRealPath("/
WEB-INF");
<integration>
<callback page="formCallback" formUrl="forms/" />
</integration>
You can then associate a form with the new PdfImageRenderer object
by calling the setForm method of the ImageRenderer class.
newPDF.setForm(form);
The following example renders the form image to the specified HTTP
servlet response:
The following example renders the form image to the specified output
stream
newTiff.setForm(form);
The following example renders the form image to the specified HTTP
servlet response, using the the LZW compression algorithm:
If you do not set a target window, then the HTTP request handler is
expected to return a response that is to be processed by the calling
script. The following table lists the valid types of content for such a
response and describes the behavior of the HttpCommand object when
a given type of response is received.
testCommand.setUrl("http://TestSuite:8080/sample.jsp");
The newly created HTTP command needs to be added into the Command
collection in order to be invoked from the rendered Form. You can
create a Toolbar button or a Form Button to call the command from
the rendered electronic form.
httpCmd.setTarget(myTarget);
With such a request you may choose to include the form data in the
request. If so, the eForm Java API provides convenience methods for
parsing the form data from the request parameters. Many such
scenarios are supported. This section describes the most common or
important.
You can parse the form data submitted from the above request and
create a Data object as follows:
The request includes a request parameter for each cell where the
parameter name is the cell name and the parameter value is the cell
value as a string in canonical format. For column cells, multiple
request parameters with the same name are included.
You can parse the form data submitted from the above request and
create a Data object:
IBM® may not offer the products, services, or features discussed in this document
in other countries. Consult your local IBM representative for information on the
products and services currently available in your area. Any reference to an IBM
product, program, or service is not intended to state or imply that only that IBM
product, program, or service may be used. Any functionally equivalent product,
program, or service that does not infringe any IBM intellectual property right may
be used instead. However, it is the user's responsibility to evaluate and verify the
operation of any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering subject matter
described in this document. The furnishing of this document does not grant you
any license to these patents. You can send license inquiries, in writing, to:
For license inquiries regarding double-byte (DBCS) information, contact the IBM
Intellectual Property Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other
country where such provisions are inconsistent with local law:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS
PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or
implied warranties in certain transactions, therefore, this statement may not apply
to you.
Any references in this information to non-IBM Web sites are provided for
convenience only and do not in any manner serve as an endorsement of those Web
sites. The materials at those Web sites are not part of the materials for this IBM
product and use of those Web sites is at your own risk.
Licensees of this program who wish to have information about it for the purpose
of enabling: (i) the exchange of information between independently created
programs and other programs (including this one) and (ii) the mutual use of the
information which has been exchanged, should contact:
IBM Corporation
J46A/G4
555 Bailey Avenue
San Jose, CA 95141-1003
U.S.A.
The licensed program described in this document and all licensed material
available for it are provided by IBM under terms of the IBM Customer Agreement,
IBM International Program License Agreement or any equivalent agreement
between us.
All statements regarding IBM's future direction or intent are subject to change or
withdrawal without notice, and represent goals and objectives only.
This information contains examples of data and reports used in daily business
operations. To illustrate them as completely as possible, the examples include the
names of individuals, companies, brands, and products. All of these names are
fictitious and any similarity to the names and addresses used by an actual business
enterprise is entirely coincidental.
COPYRIGHT LICENSE:
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the
United States, other countries, or both.
Other company, product, and service names may be trademarks or service marks
of others.
SC19-3247-00