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 import net.sf.jiffie.IHTMLInputElement;
22
23 /***
24 * This action point checks any checkbox in a form or not.
25 *
26 * Some example uses might be:
27 *
28 * Checking <input type="checkbox" name="checkBox1" value="one"</a>
29 * <pre><source>
30 * <ie-set-checkbox functionId="Set a checkbox in a given form to checked"
31 * name="checkBox1"
32 * checked="true"
33 * form="testForm"/>
34 * </source></pre>
35 *
36 * Checking <input type="checkbox" name="checkBox1" value="one"</a> that doesn't exist in a form
37 * <pre><source>
38 * <ie-set-checkbox functionId="Set a checkbox in a given form to checked"
39 * name="checkBox1"
40 * checked="true"/>
41 * </source></pre>
42 *
43 * Unchecking <input type="checkbox" name="checkBox3"</a>
44 * <pre><source>
45 * <ie-set-checkbox functionId="Uncheck a given checkbox"
46 * name="checkBox3"
47 * checked="false"
48 form="testForm"/>
49 * </source></pre>
50 *
51 * Checking a checkbox with the same name, but different value:
52 * <input type="checkbox" name="cb1" value="1"</a><input type="checkbox" name="cb1" value="2"</a>
53 * <pre><source>
54 * <ie-set-checkbox functionId="Ckeck a checkbox 'cb1' with the value '1'. Notice that two checkboxes have the same name."
55 * name="cb1"
56 * value="1"
57 * checked="true"
58 * form="testForm"/>
59 * </source></pre>
60 * NOTE: <b>This tag does not currently support the xpath attribute nor the nested ie-attribute tags.</b>
61 * @jameleon.function name="ie-set-checkbox" type="action"
62 * @jameleon.step Find the given form and set it as the working form
63 * @jameleon.step Find the given checkbox and set it to checked (checked=true) or unchecked (checked=false)
64 */
65 public class IESetCheckboxTag extends IEFireEventTag {
66
67 /***
68 * The name of the checkbox field
69 * @jameleon.attribute required="true" contextName="ieSetCheckboxName"
70 */
71 protected String name;
72 /***
73 * The value of the checkbox field. If set, then the name and value are used to
74 * identify the checkbox to check or uncheck
75 * @jameleon.attribute required="false" contextName="ieSetCheckboxValue"
76 */
77 protected String value;
78 /***
79 * Check the checkbox if set to true; uncheck the checkbox if set to false.
80 * @jameleon.attribute required="true" contextName="ieSetCheckboxValue"
81 */
82 protected boolean checked;
83 /***
84 * The name, id or index of the field
85 * @jameleon.attribute contextName="ieSetCheckboxForm"
86 */
87 protected String form;
88
89 public void testBlock() {
90 if (htmlElement != null ||
91 xpath != null ||
92 getParamLength() > 0) {
93 throw new RuntimeException("htmlElement, xpath and ie-attribute are not supported by this tag");
94 }
95 setWorkingForm(form);
96 IHTMLInputElement checkbox = null;
97 if ( value != null ) {
98 checkbox = setCheckboxWithNameAndValue(name, value, checked);
99 }else{
100 checkbox = setCheckbox(name, checked);
101 }
102 fireEvent(checkbox);
103 }
104 }