Java Reference
In-Depth Information
You should note several things. The for loop's counter (ctr) is initialized to zero to correspond to the index value
of the array's first position/bucket. The loops test condition checks that the count is less than the length of the array.
Think about that. If the array has a length of three, the largest index value in the array is two (i.e., the array has three
values with index values of 0, 1, and 2). We want the for to execute three times for the counter values of 0, 1, and 2. So
we want the for to only execute when the variable ctr is less than the length of the array (3).
Inside the loop, the constant text that comprises the beginning of the start OPTION tag (optionTagStart) is
concatenated to the state value stored in the first position of the array (i.e., FL). This means that after the first
statement in the loop, optionTags has the following value:
<OPTION value="FL
The if statement then compares the value in the first array position to the variable select-ed's value. Based on
whether they are equal or not, either the optionSelected or optionNotSelected string is concatenated to (and finishes)
the start OPTION tag. In this case, we'll assume that no attribute value was specified by the page designer and that the
value of selected is the default value FL. This means that the characters stored in optionSelected are appended to
optionTags resulting in a value of:
<OPTION value="FL" selected>
Next, the state abbreviation to appear in the drop-down menu (i.e., the value in position 0 of the array) and the
end tag are appended to optionTags, resulting in a character string of:
<OPTION value="FL" selected>FL</OPTION>
The OPTION tag for the first state value is converted to a String and written to the JSP. The contents of optionTags
is deleted and the loop begins again (the counter value is incremented by one, compared against the length of the
array, etc). The loop will execute two more times and the HTML for the two remaining state values will be embedded
into the JSP.
Because of the array and loop, if five states had to be added, five state values would simply be added to the array
definition. No other java code or HTML statements would be needed to add the five states.
4.
Save TNTStateDDM.
Tutorial: Defining and Using the Custom Tag
We can now define and use the tag
1.
In TNT.tld add the following XML after the getEmp tag definition:
<tag>
<name>stateDDM</name>
<tagclass>c11.TNTStateDDM</tagclass>
<attribute>
<name>selected</name>
<required>false</required >
</attribute>
</tag>
2.
Save TNT.tld.
3.
Bring up c11/EnterEmpInfoForm.html in the Page Designer and click on the state input field.
4.
Switch to the Source view.
 
Search WWH ::




Custom Search