View Javadoc

1   /*
2       Jameleon HtmlUnit plug-in - A plug-in that uses HtmlUnit to drive web sites
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111AssertLevel.NO_FUNCTION07 USA
18  */
19  package net.sf.jameleon.plugin.htmlunit.tags;
20  
21  import com.gargoylesoftware.htmlunit.html.HtmlInput;
22  import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
23  
24  /***
25   * This tag is used to set or unset checkboxes defined by a given XPath expression.
26   * 
27   * <p>
28   * To use XPath to check a radio button named <b>rb_1</b> that exists in a form with the name <b>testform</b>:<br/>
29   * <pre><source>
30   *     &lt;htmlunit-set-radio-button
31   *            functionId="Check the radio button named rb_1"
32   *            xpath="//form[@name='testform']/input[@name='rb_1']"
33   *            checked="true"/>
34   * </source></pre>
35   * </p>
36   * <p>
37   * To use XPath to uncheck a checkbox named <b>cb_1</b> that exists in a form with the name <b>testform</b>:
38   * <pre><source>
39   *     &lt;htmlunit-set-radio-button
40   *            functionId="Uncheck the radio button named rb_1"
41   *            xpath="//form[@name='testform']/input[@name='rb_1']"
42   *            checked="false"/>
43   * </source></pre>
44   * </p>
45   * <p>
46   * To use the form and the field name to check a radio button named <b>rb_1</b> that exists in a form with the name <b>testform</b>:
47   * <pre><source>
48   *     &lt;htmlunit-set-radio-button
49   *            functionId="Check the radio button named rb_1"
50   *            form="testform"
51   *            fieldName="rb_1"
52   *            checked="true"/>
53   * </source></pre>
54   * </p>
55   * <p>
56   * To use the form, field name and value to check a radio button named <b>rb_1</b> with the value
57   * <b>rb_val1</b> that exists in a form with the name <b>testform</b>:
58   * <pre><source>
59   *     &lt;htmlunit-set-radio-button
60   *            functionId="Check the radio button named rb_1"
61   *            form="testform"
62   *            fieldName="rb_1"
63   *            value="rb_val1"
64   *            checked="true"/>
65   * </source></pre>
66   * </p>
67   * @jameleon.function name="htmlunit-set-radio-button" type="action"
68   */
69  public class HtmlUnitSetRadioButtonTag extends AbstractHtmlUnitCheckFieldTag{
70  
71      protected void checkFieldWithValue(String fieldName, String value, boolean check){
72          setRadioButton(fieldName, value, check);
73      }
74  
75      protected void checkField(HtmlInput inputField, boolean check){
76          ((HtmlRadioButtonInput)inputField).setChecked(checked.booleanValue());
77      }
78  
79      protected String getInputType(){
80          return "radio";
81      }
82  
83  }