Chapter 5. Building the base scenario: Stage 2 199
<wsdl:output name="GETCUSTOMERLISTResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://WPFormsRedpaper" use="encoded"></wsdlsoap:body>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GETCUSTINFO">
<wsdlsoap:operation soapAction=""></wsdlsoap:operation>
<wsdl:input name="GETCUSTINFORequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://WPFormsRedpaper" use="encoded"></wsdlsoap:body>
</wsdl:input>
<wsdl:output name="GETCUSTINFOResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://WPFormsRedpaper" use="encoded"></wsdlsoap:body>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CustomerInfoService">
<wsdl:port binding="impl:WPFormsCustSoapBinding" name="WPFormsCust">
<wsdlsoap:address
location="http://vmforms1.cam.itso.ibm.com:8085/WpfWsCustomerT/services/WPFormsCust"></wsdlsoap:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
</wsdl>
</webservices>
5.6.3 Calling the Web services
There are two types of Web services that we are using to prepopulate the form.
򐂰 Web services returning simple type objects
򐂰 Web services returning complex type objects
While the Integration of Web services returning a simple type object can be accomplished
using custom computes on the field level, Web services returning complex objects have to be
integrated into your XML Data Model.
Web services returning simple type objects
Web services returning simple type objects send back a single string as return value. This
value can then either be filled as a single value into a field or split up into several values as
choices for a pop-up menu for example. In our scenario we use this type of Web services to
prepopulate two pop-up menus:
򐂰 Customer selection pop-up
򐂰 Product item selection pop-up
To parse the single string returned from the Web service into a choices list for our pop-up
menus we had to realize a nested loop functionality as a custom option in XFDL as described
in the following section.
200 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
For loops and nesting loops in XFDL
The For function creates a counter that you can use to simulate a “for loop” (as found in most
programming languages).
This function uses an option in your form (such as a custom option) as an index that stores
the current count of the loop. As the loop counts, it sets this option to the current count.
For example, if the for loop counted from 1 to 3, it would first set the option to 1, then to 2,
then to 3.
You can then trigger other action in the form based on the value of this option. For example,
you could use the toggle function to detect each change in the option's value, and to update
some aspect of the form each time.
A form with a for loop will begin counting that loop as soon as the form opens, unless the loop
itself relies on a triggering event, such as a key-press event or a toggle function.
You can create a loop that counts once by setting the initial count and the final count to be
equal. For example, a loop that counts from 1 to 1 will count once.
To create a nested loop, you must trigger the second loop off the value of the first. For
example, your first loop might change the value of the custom:loop1 option. You can then
create a toggle function that detects any change in the custom:loop1 option, and that triggers
its own loop, as shown in Example 5-30.
Example 5-30 Nesting Loops in XFDL
toggle(custom:loop1) == '1' ? for('custom:loop2', '1', '5') : ''
The second loop is triggered each time the value of custom:loop1 changes. In other words,
the second loop is triggered each time the first loop counts once. Additionally, the second loop
will process completely before processing of the first loop resumes. In this case, that means
the second loop will count from 1-5 before the first loop counts again.
Example 5-31 shows the custom computes used in the customer selection pop-up to
prepopulate the choices by consuming the Customer Data Web service described in 5.3,
“Web services” on page 168.
Example 5-31 Nested Loop to prepopulate Customer pop-up using a Web service
<custom:getCustomerChoices xfdl:compute="
(toggle(custom:CustomerChoicesCounter) == '1' and (custom:CustomerChoicesCounter == '0'))
or (CustomerChoices_1.value=='')
? set('custom:CustomerChoicesList', CustomerInfoService_WPFormsCust.GETCUSTOMERLIST('') +. '~')
+ for('custom:CustomerChoicesCounter', '1', strlen(custom:CustomerChoicesList))
: ''">
</custom:getCustomerChoices>
<custom:getCustomerChoices2 xfdl:compute="
Tip: When creating the option that acts as an index for the loop, ensure that the starting
value of the option does not equal the starting value of the loop. If it does, your loop will
work incorrectly, since setting the first count will not result in a detectable change.
For example, you might create a loop that counts from 1-5, and your index might be set to
a value of 1. In this case, the first count of the loop will set the index to 1, but since the
index already equals 1, there will be no detectable change to the value. This means that
any toggle function used to detect a change in that value will not fire.

Get IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.