182 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
The basic idea is here to get the original XFDL information (template), transform it adding
external data to the form and then send it to the client. Assuming an invocation URL fired from
the client browser to open a form, in a servlet environment, prepopulation will occur usually in
the doGet method. The URL must now point to the servlet (not directly to the stored template
on file system) and contain a reference to the chosen template.
Form download based on a POST action fired by a browser or another system would be
handled in the doPost method. This will not occur in our scenario, but it is possible to do so.
The coding in Example 5-17 gives a simple example of how prepopulation can be done in the
doGet method.
Example 5-17 Prepopulation executed in doGet servlet method
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
//get the tem plate oath from the request parameter “template=”
String formTemplate = request.getParameter("template");
FileInputStream fis = new FileInputStream(formTemplate);
XFDL theXFDL = IFSSingleton.getXFDL();
FormNodeP theForm = theXFDL.readForm(fis,XFDL.UFL_SERVER_SPEED_FLAGS);
....
//Set some internal values like this
//address the internal element to update using xfdl specific pathes.
String mgrThreshold = “10000”;
theForm.setLiteralByRefEx(null,
"global.global.xmlmodel[xfdl:instances][3][null:BusinessRuleParams][null:QuoteLevelOneThres
hold]",0, null, null, mgrThreshold);
.....
//Return the prepopulated form
response.setContentType("application/vnd.xfdl");
theForm.writeForm(response.getOutputStream(), null, 0);
} catch (Exception doGetE) {
System.out.println("SubmissionServlet: doGet: Exception processing request: "
+ doGetE.toString());
returnText(response,"SubmissionServlet: doGet: Exception occured: "
+ doGetE.toString(), "text/plain");
{
}
As discussed in Stage 1, it is a best practice to access form data using data instances, not
field values. The example above does access an data instance (in the code, see reference
global.global.xmlmodel[xfdl:instances][3][null:BusinessRuleParams][null:QuoteLevelOneThresh
old
), but the instance is selected by position ([3])- not by name. This can break when
instances are moved in the form. As in value extraction, there is a better way to reference the
instance by instance ID.
The next example shows how to address a field value synchronized with an XFDL data
instance by position or by name. See the following data instance in the XFDL form
(Example 5-18).