1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jameleon.plugin.jiffie.tags;
21
22 import java.util.List;
23
24 /***
25 * Sets the value(s) of any select field.
26 * Only one of optionText, optionValue, or optionIndex can set. In other words, they
27 * can't be used in conjunction with one another.
28 *
29 * Some example uses might be:
30 *
31 * Selecting
32 * <pre><source>
33 * <select name="selectField">
34 * <option value="1">one</option>
35 * <option value="2">two</option>
36 * <option value="3">three</option>
37 * <option value="4">four</option>
38 * </select>
39 * </source></pre>
40 *
41 * <pre><source>
42 * <ie-set-select-field functionId="Set the select field not in a form to the value displayed as 'two'"
43 * name="selectField"
44 * optionText="two"/>
45 * </source></pre>
46 *
47 * Selecting multiple values from:
48 * <pre><source>
49 * <select name="selectField" mulitple>
50 * <option value="1">one</option>
51 * <option value="2">two</option>
52 * <option value="3">three</option>
53 * <option value="4">four</option>
54 * </select>
55 * </source></pre>
56 *
57 * <pre><source>
58 * <map-variable toVariable="fieldValues" variableType="List">
59 * <variable-value>1</variable-value>
60 * <variable-value>4</variable-value>
61 * </map-variable>
62 * <ie-set-select-field functionId="Set mulitple values in the the select field via the value '1' and '4'"
63 * name="selectField"
64 * optionValue="${fieldValues}"/>
65 * </source></pre>
66 *
67 * <pre><source>
68 * <ie-set-select-field functionId="Set the select field to the value displayed as 'two'"
69 * name="selectField"
70 * optionText="two"
71 * form="testForm"/>
72 * </source></pre>
73 *
74 * <pre><source>
75 * <ie-set-select-field functionId="Set the select field to the value '3' as defined by its value attribute"
76 * name="selectField"
77 * optionValue="3"
78 * form="testForm"/>
79 * </source></pre>
80 * <pre><source>
81 * <ie-set-select-field functionId="Set the select field to the fourth selection"
82 * name="selectField"
83 * optionIndex="3"
84 * form="testForm"/>
85 * </source></pre>
86 * NOTE: <b>This tag does not currently support the xpath attribute nor the nested ie-attribute tags.</b>
87 * @jameleon.function name="ie-set-select-field" type="action"
88 * @jameleon.step Find the given form and set it as the working form
89 * @jameleon.step Find the given select field and set it's value
90 * @author Christian Hargraves
91 * @author Pravin Bhujbal
92 */
93 public class IESetSelectFieldTag extends IEFireEventTag {
94
95 /***
96 * The name of the text field
97 * @jameleon.attribute required="true" contextName="ieSetSelectFieldName"
98 */
99 protected String name;
100 /***
101 * The displayed text of the option to select.
102 * This attribute can have multiple values. In which case each one will be validated.
103 * @jameleon.attribute contextName="ieSetSelectFieldOptionText"
104 */
105 protected List optionText;
106 /***
107 * The value attribute of the option tag to select.
108 * This attribute can have multiple values. In which case each one will be validated.
109 * NOTE: This is not the text that appears in the drop-down list.
110 * Instead it is the value attribute of the option tag which should be
111 * nested inside the select tag.
112 * @jameleon.attribute contextName="ieSetSelectFieldOptionValue"
113 */
114 protected List optionValue;
115 /***
116 * The index of the option to select. For example, to select the 2nd option, pass in 1
117 * This attribute can have multiple values. In which case each one will be validated.
118 * @jameleon.attribute contextName="ieSetSelectFieldOptionIndex"
119 */
120 protected List optionIndex;
121 /***
122 * The name, id or index of the field
123 * @jameleon.attribute contextName="ieSetSelectFieldForm"
124 */
125 protected String form;
126
127 public void testBlock() {
128 if (htmlElement != null ||
129 xpath != null ||
130 getParamLength() > 0) {
131 throw new RuntimeException("htmlElement, xpath and ie-attribute are not supported by this tag");
132 }
133 if (optionText != null &&
134 optionValue != null &&
135 optionIndex != null) {
136 throw new RuntimeException("Onle of optionIndex, optionValue and optionText can be used at a time.");
137 }
138 setWorkingForm(form);
139 if (optionText != null && optionText.size() > 0) {
140 fireEvent(setSelectFieldOptionTextValues(name, optionText));
141 }else if (optionIndex != null && optionIndex.size() > 0) {
142 int[] indexes = new int[optionIndex.size()];
143 for (int i = 0; i < indexes.length; i++) {
144 indexes[i] = (new Integer((String)optionIndex.get(i)).intValue());
145 }
146 fireEvent(setSelectFieldOptionIndexes(name, indexes));
147 }else if (optionValue != null && optionValue.size() > 0) {
148 fireEvent(setSelectFieldOptionValues(name, optionValue));
149 }else{
150 fail("You must define one of the following 'displayedText', 'optionIndex', or 'optionValue'");
151 }
152 }
153 }