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  /***
22   * A tag which sets a text field to the provided value.
23   * <br/>
24   * To use XPath to set a text field named <b>testTextField</b> that exists in a form with the name <b>testform</b>:
25   * <pre><source>
26   *     &lt;htmlunit-set-text-field
27   *            functionId="Set the testTextField field to 'some value'"
28   *            xpath="//form[@name='testform']/input[@name='testTextField']"
29   *            value="some value"/>
30   * </source></pre>
31   * To use XPath to set a text field named <b>testTextField</b> that doesn't exist in a form:
32   * <pre><source>
33   *     &lt;htmlunit-set-text-field
34   *            functionId="Set the testTextField field to 'some value'"
35   *            xpath="//input[@name='testTextField']"
36   *            value="some value"/>
37   * </source></pre>
38   * To to set a text field named <b>testTextField</b> that exists in a form with id or name of <b>form_test</b> w/o using XPath:
39   * <pre><source>
40   *     &lt;htmlunit-set-text-field
41   *            functionId="Set the testTextField field to 'some value'"
42   *            form="form_test"
43   *            fieldName="testTextField"
44   *            value="some value"/>
45   * </source></pre>
46   * To to set a text field named <b>testTextField</b> that exists in the 2nd form <b>form_test</b> w/o using XPath:
47   * <pre><source>
48   *     &lt;htmlunit-set-text-field
49   *            functionId="Set the testTextField field to 'some value'"
50   *            form="2"
51   *            fieldName="testTextField"
52   *            value="some value"/>
53   * </source></pre>
54   * To to set a text field named <b>testTextField</b> that exists in form define by <b>//table/tr[3]/td/form</b> XPath:
55   * <pre><source>
56   *     &lt;htmlunit-set-text-field
57   *            functionId="Set the testTextField field to 'some value'"
58   *            form="//table/tr[3]/td/form"
59   *            fieldName="testTextField"
60   *            value="some value"/>
61   * </source></pre>
62   * @jameleon.function name="htmlunit-set-text-field" type="action"
63   */
64  public class HtmlUnitSetTextFieldTag extends AbstractHtmlUnitSetInputFieldTag{
65  
66      protected String getInputType(){
67          return "text";
68      }
69  
70      protected void setFieldValueInForm(){
71          if (value != null) {
72              setTextField(fieldName, value);
73          }
74      }
75  
76  }