KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > Hidden


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16
17 package com.google.gwt.user.client.ui;
18
19 import com.google.gwt.user.client.DOM;
20 import com.google.gwt.user.client.Element;
21
22 /**
23  * Represents a hidden field in an HTML form.
24  */

25 public class Hidden extends Widget implements HasName {
26
27   /**
28    * Constructor for <code>Hidden</code>.
29    */

30   public Hidden() {
31     Element e = DOM.createElement("input");
32     setElement(e);
33     DOM.setElementProperty(e, "type", "hidden");
34   }
35
36   /**
37    * Constructor for <code>Hidden</code>.
38    *
39    * @param name name of the hidden field
40    */

41   public Hidden(String JavaDoc name) {
42     this();
43     setName(name);
44   }
45
46   /**
47    * Constructor for <code>Hidden</code>.
48    *
49    * @param name name of the hidden field
50    * @param value value of the hidden field
51    */

52   public Hidden(String JavaDoc name, String JavaDoc value) {
53     this(name);
54     setValue(value);
55   }
56
57   /**
58    * Gets the default value of the hidden field.
59    *
60    * @return the default value
61    */

62   public String JavaDoc getDefaultValue() {
63     return DOM.getElementProperty(getElement(), "defaultValue");
64   }
65
66   /**
67    * Gets the id of the hidden field.
68    *
69    * @return the id
70    */

71   public String JavaDoc getID() {
72     return DOM.getElementProperty(getElement(), "id");
73   }
74
75   /**
76    * Gets the name of the hidden field.
77    *
78    * @return the name
79    */

80
81   public String JavaDoc getName() {
82     return DOM.getElementProperty(getElement(), "name");
83   }
84
85   /**
86    * Gets the value of the hidden field.
87    *
88    * @return the value
89    */

90   public String JavaDoc getValue() {
91     return DOM.getElementProperty(getElement(), "value");
92   }
93
94   /**
95    * Sets the default value of the hidden field.
96    *
97    * @param defaultValue default value to set
98    */

99   public void setDefaultValue(String JavaDoc defaultValue) {
100     DOM.setElementProperty(getElement(), "defaultValue", defaultValue);
101   }
102
103   /**
104    * Sets the id of the hidden field.
105    *
106    * @param id id to set
107    */

108   public void setID(String JavaDoc id) {
109     DOM.setElementProperty(getElement(), "id", id);
110   }
111
112   /**
113    * Sets the name of the hidden field.
114    *
115    * @param name name of the field
116    */

117   public void setName(String JavaDoc name) {
118     if (name == null) {
119       throw new NullPointerException JavaDoc("Name cannot be null");
120     } else if (name.equals("")) {
121       throw new IllegalArgumentException JavaDoc("Name cannot be an empty string.");
122     }
123     DOM.setElementProperty(getElement(), "name", name);
124   }
125
126   /**
127    * Sets the value of the hidden field.
128    *
129    * @param value value to set
130    */

131   public void setValue(String JavaDoc value) {
132     DOM.setElementProperty(getElement(), "value", value);
133   }
134 }
135
Popular Tags