KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > javascript > host > FormField


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit.javascript.host;
39
40 import java.io.IOException JavaDoc;
41
42 import org.mozilla.javascript.Function;
43
44 import com.gargoylesoftware.htmlunit.html.ClickableElement;
45 import com.gargoylesoftware.htmlunit.html.HtmlElement;
46
47 /**
48  * Base class for all javascript object correspondig to form fields.
49  *
50  * @version $Revision: 100 $
51  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
52  * @author <a HREF="mailto:cse@dynabean.de">Christian Sell</a>
53  * @author Marc Guillemot
54  * @author Chris Erskine
55  */

56 public class FormField extends FocusableHostElement {
57
58     private static final long serialVersionUID = 3712016051364495710L;
59
60
61     /**
62      * Return the value of the javascript attribute "value".
63      *
64      *@return The value of this attribute.
65      */

66     public String JavaDoc jsxGet_value() {
67         return getHtmlElementOrDie().getAttributeValue( "value" );
68     }
69
70
71     /**
72      * Set the value of the javascript attribute "value".
73      *
74      *@param newValue The new value.
75      */

76     public void jsxSet_value( final String JavaDoc newValue ) {
77         getHtmlElementOrDie().setAttributeValue( "value", newValue );
78     }
79
80
81     /**
82      * Return the value of the javascript attribute "name".
83      *
84      *@return The value of this attribute.
85      */

86     public String JavaDoc jsxGet_name() {
87         return getHtmlElementOrDie().getAttributeValue( "name" );
88     }
89     
90     /**
91      * Set the value of the javascript attribute "name".
92      *
93      *@param newName The new name.
94      */

95     public void jsxSet_name( final String JavaDoc newName ) {
96         getHtmlElementOrDie().setAttributeValue( "name", newName );
97     }
98
99
100     /**
101      * Return the value of the javascript attribute "form".
102      *
103      *@return The value of this attribute.
104      */

105     public Form jsxGet_form() {
106         return (Form)getScriptableFor(getHtmlElementOrDie().getEnclosingForm());
107     }
108
109     /**
110      * Return the value of the javascript attribute "type".
111      *
112      *@return The value of this attribute.
113      */

114     public String JavaDoc jsxGet_type() {
115         return getHtmlElementOrDie().getAttributeValue("type");
116     }
117
118     /**
119      * Set the onchange event handler for this element.
120      * @param onchange the new handler
121      */

122     public void jsxSet_onchange(final Function onchange) {
123         getHtmlElementOrDie().setEventHandler("onchange", onchange);
124     }
125
126     /**
127      * Get the onchange event handler for this element.
128      * @return <code>org.mozilla.javascript.Function</code>
129      */

130     public Function jsxGet_onchange() {
131         return getHtmlElementOrDie().getEventHandler("onchange");
132     }
133
134     /**
135      * Click this element. This simulates the action of the user clicking with the mouse.
136      * @throws IOException if this click triggers a page load that encouters problems
137      */

138     public void jsxFunction_click() throws IOException JavaDoc {
139         ((ClickableElement) getHtmlElementOrDie()).click();
140     }
141
142     /**
143      * Select this element.
144      */

145     public void jsxFunction_select() {
146         getLog().debug( "Input.jsxFunction_select() not implemented" );
147     }
148
149     /**
150      * Return true if this element is disabled.
151      * @return True if this element is disabled.
152      */

153     public boolean jsxGet_disabled() {
154         return getHtmlElementOrDie().isAttributeDefined("disabled");
155     }
156
157
158     /**
159      * Set whether or not to disable this element
160      * @param disabled True if this is to be disabled.
161      */

162     public void jsxSet_disabled( final boolean disabled ) {
163         final HtmlElement element = getHtmlElementOrDie();
164         if( disabled ) {
165             element.setAttributeValue("disabled", "disabled");
166         }
167         else {
168             element.removeAttribute("disabled");
169         }
170     }
171
172     /**
173      * Return the value of the tabindex attribute.
174      * @return the value of the tabindex attribute.
175      */

176     public String JavaDoc jsxGet_tabindex() {
177         return getHtmlElementOrDie().getAttributeValue("tabindex");
178     }
179 }
180
181
Popular Tags