<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ page import="java.util.*"; %> <%@ page import="commonj.sdo.DataObject"; %> <%try { %> <% String[] prices = {"0.0"}; // default extra charge String[] freebies = {"Calendar"}; // default gift, if no or empty gift lift is passed to the task // ******************************************************************************* // Get the message map from the session // The message map has been put into the session in the input jsp // ******************************************************************************* Map inputData = (Map)session.getAttribute("inputData"); if( inputData != null) { // **************************************************************************************** // determine the size of the promotional gift list // Note: the data have been transported from the input jsp to this jsp // the data values in the map are stored in the form (String, String), where // - the first string is a path expression // - the second string represents the value // **************************************************************************************** // **************************************************************************************** // starting with WPS version 6.1, the first array element has the index 1. // To make this code version independent, check whether index 0 exists (older version). // Then memorize the index oif the first element. // **************************************************************************************** int indexOfFirstElement = 0; String key = "/selectPromotionalGiftRequest/promotionalGiftList[" + indexOfFirstElement + "]/description"; if ( inputData.containsKey(key) == false ) indexOfFirstElement = 1; int size = 0; key = "/selectPromotionalGiftRequest/promotionalGiftList[" + (size+indexOfFirstElement) + "]/description"; while ( inputData.containsKey(key) ) { size++; key = "/selectPromotionalGiftRequest/promotionalGiftList[" + (size+indexOfFirstElement) + "]/description"; } // ************************************************************************************************************** // When the size of the promotional gift list has been determined the values are stored in arrays. // These arrays are used to initialize a javascript variable and a HTML dropdown list // ************************************************************************************************************** if(size > 0) { prices = new String[size]; freebies = new String[size]; for(int i = 0 ; i < size; i++) { String priceKey = "/selectPromotionalGiftRequest/promotionalGiftList[" + (i+indexOfFirstElement) + "]/extraCharge"; String freebieKey = "/selectPromotionalGiftRequest/promotionalGiftList[" + (i+indexOfFirstElement) + "]/description"; prices[i] = (String)inputData.get(priceKey); freebies[i] = (String)inputData.get(freebieKey); } } } // ********************************************************************************************* // We have to consider that data was saved in the task during interaction. // The dropdown list and the price field have to be initialized accordingly. // see HTML section // ********************************************************************************************* String selectedFreebie = null; // when the dropdown list is initalized the code tests against this value int selectedIndex = 0; // will be updated during initalization of the dropdon list //*********************************************************************** // access the outpu message of the task // consider the case that this data objects were not initialized before //*********************************************************************** DataObject output = (DataObject)request.getAttribute("message"); if(output != null) { DataObject selectPromotionalGiftResponse = output.getDataObject("selectPromotionalGiftResponse"); if(selectPromotionalGiftResponse != null) { DataObject promotionalGift = selectPromotionalGiftResponse.getDataObject("promotionalGift"); if(promotionalGift != null) { selectedFreebie = promotionalGift.getString("description"); } } } %>

A promotional gift is presented to you! - Just select your gift and enter your personal information in the form. The gift will be delivered today.

Note: Some of the gifts cost a little extra charge. If you select such a gift, please enter your credit card information.

Name:
Address:
Promotional gift:
Extra charge:
Credit card number:
Credit card company:
valid thru:

You have selected the following gift:

Name: ${messageMap['/selectPromotionalGiftResponse/name']}
Address: ${messageMap['/selectPromotionalGiftResponse/address']}
Promotional gift: ${messageMap['/selectPromotionalGiftResponse/promotionalGift/description']}
Extra charge: ${messageMap['/selectPromotionalGiftResponse/promotionalGift/extraCharge']}
Credit card number: ${messageMap['/selectPromotionalGiftResponse/creditCardInformation/cardNumber']}
Credit card company: ${messageMap['/selectPromotionalGiftResponse/creditCardInformation/cardCompany']}
valid thru: ${messageMap['/selectPromotionalGiftResponse/creditCardInformation/valid']}
<% } catch (Exception exception) { System.out.println(exception); exception.printStackTrace(System.out); } %>