Você está na página 1de 8

Creating a Sample Questionnaire with Multiple Choice

Answers using IBM WebSphere Portlet Factory


Feb, 2010

© Copyright International Business Machines Corporation 2010. All rights reserved.

This article with the accompanying sample shows you how to use IBM WebSphere
Portlet Factory Version 6 (hereafter called Portlet Factory) to create a sample
questionnaire.

This article is one in a collection of articles and samples that illustrate techniques for
developing with Portlet Factory. See the Portlet Factory Product Documentation page
for a complete list of these. For an introduction to developing with Portlet Factory, you
may want look at the introductory tutorials that are available both in the product help and
on that web site.

Prerequisites
You should have a basic familiarity with Portlet Factory (version 6.1.5 or higher is
required for this sample) and be able to create and run Portlet Factory models.
The key builders contained in the sample are the Data Page, Data Column Modifier, Data
Field Modifier, and the Lookup Table builder.

Sample description
The Sample Questionnaire model demonstrates one of the possible solutions for
presenting data containing multiple Label/Value pairs. In this sample, the Label/Value
pairs are the question answers defined with a text Label and corresponding letter Value.
For example, <Answer><Label>Jan</Label><Value>a</Value></Answer>

The implementation for presenting the question Label/Value pairs is to use the Lookup
Table builder. Also, the question page Data Column Modifier builder defines a Loop
Variable Name so this variable can be reused in the response page to resolve the answer
Label/Value pairs.

The other technique demonstrated in the Sample Questionnaire model is to lookup the
Label based on a given value when gathering the question responses. This is
accomplished by reusing the existing Lookup Table builder.

The following sections detail some of the techniques illustrated in the sample code.
Creating the Questions Page
The source data for the sample model questions is contained in a Variable builder with
type of XML (see Figure 1). This XML data is then mapped to HTML tags on a page
using the Data Page, Data Column Modifier, and Data Field Modifier builders.

Figure 1. Questions Page – XML Data

<RowSet>
<Row>
<Question>What is your favorite month of the year?</Question>
<Result/>
<Answers>
<Answer><Label>Jan</Label><Value>a</Value></Answer>
<Answer><Label>Feb</Label><Value>b</Value></Answer>
<Answer><Label>March</Label><Value>c</Value></Answer>
<Answer><Label>April</Label><Value>d</Value></Answer>
<Answer><Label>May</Label><Value>e</Value></Answer>
<Answer><Label>June</Label><Value>f</Value></Answer>
<Answer><Label>July</Label><Value>g</Value></Answer>
<Answer><Label>Aug</Label><Value>h</Value></Answer>
<Answer><Label>Sept</Label><Value>i</Value></Answer>
<Answer><Label>Oct</Label><Value>j</Value></Answer>
<Answer><Label>Nov</Label><Value>k</Value></Answer>
<Answer><Label>Dec</Label><Value>l</Value></Answer>
</Answers>
</Row>
<Row>
<Question>Where would you take a New England vacation?</Question>
<Result/>
<Answers>
<Answer><Label>Massachusetts</Label><Value>a</Value></Answer>
<Answer><Label>Maine</Label><Value>b</Value></Answer>
<Answer><Label>New Hampshire</Label><Value>c</Value></Answer>
<Answer><Label>Vermont</Label><Value>d</Value></Answer>
<Answer><Label>Connecticut</Label><Value>e</Value></Answer>
<Answer><Label>Rhode Island</Label><Value>f</Value></Answer>
</Answers>
</Row>
<Row>
<Question>What is your preferred climate?</Question>
<Result/>
<Answers>
<Answer><Label>Hot</Label><Value>a</Value></Answer>
<Answer><Label>Warm</Label><Value>b</Value></Answer>
<Answer><Label>Cold</Label><Value>c</Value></Answer>
<Answer><Label>Cool</Label><Value>d</Value></Answer>
</Answers>
</Row>
</RowSet>
The Data Column Modifier builder can be set to hide the XML Schema Answers
(Choices) from view as seen in Figure 2. The Answers are formatted to a Radio Button
Group using the Data Field Modifier.

Figure 2. Questions Page – Data Column Modifier – Settings for Add and Delete Row
Operations

Another important setting in the Data Column Modifier is to provide a definition for the
Loop Variable Name (QLoopVar) (see Figure 3). This Loop Variable Name will be
reused later in the model for the Responses page setup.

Figure 3. Questions Page – Data Column Modifier - Advanced


The Data Field Modifier uses the Lookup Table and defines the display type for the
Answers (Choices) to a Radio Button Group (see Figure 4).

Figure 4. Questions Page – Data Field Modifier – Field Settings

The Lookup Table is used to map the Answer Label/Value pairs as seen in Figure 5.

Figure 5. Questions Page – Lookup Table


The Questions Page is shown in Figure 6.

Figure 6. Sample Questionnaire – Questions Page


Creating the Results Page
The results page utilizes the existing Table Lookup builder to map questionnaire response
Label/Value pairs to HTML tags. The other supporting builders for the results page are
the Data Page, Data Column Modifier, and Data Field Modifier builders.

As in the Questions Page setup, notice the Results Page Data Column Modifier-
Advanced section defines the Loop Variable Name with the existing variable QLoopVar
(see Figure 1).

Figure 1. Results Page – Data Column Modifier - Advanced

The Data Field Modifier reuses the existing Lookup Table to interpret the Results values
(see Figure 2).

Figure 2. Results Page – Data Field Modifier – Field Settings


The Results page is shown in Figure 3.
Figure 3. Results Page
Instructions for running the sample
To run the sample application:
1. Download the sample ZIP file and import it into a project using the File,
Import, WebSphere Portlet Factory Archive command.
2. Open the SampleQuestionnaire model and run with WASCE which will
present the Sample Questionnaire – Question page.

Resources
WebSphere Portlet Factory product documentation
http://www.ibm.com/developerworks/websphere/zones/portal/portletfactory/proddoc.html

WebSphere Portlet Factory support


http://www.ibm.com/software/genservers/portletfactory/support/

developerWorks forums
http://www.ibm.com/developerworks/forums/wsdd_forums.jsp

Trademarks
• DB2, IBM, Lotus, Tivoli, Rational, and WebSphere are trademarks or registered
trademarks of IBM Corporation in the United States, other countries, or both.
• Windows and Windows NT are registered trademarks of Microsoft Corporation in the
United States, other countries, or both.
• Java and all Java-based trademarks and logos are trademarks or registered 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.

Você também pode gostar