001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016:
017: package com.google.gwt.user.client.ui;
018:
019: import com.google.gwt.user.client.DOM;
020: import com.google.gwt.user.client.Element;
021:
022: /**
023: * Represents a hidden field in an HTML form.
024: */
025: public class Hidden extends Widget implements HasName {
026:
027: /**
028: * Constructor for <code>Hidden</code>.
029: */
030: public Hidden() {
031: Element e = DOM.createElement("input");
032: setElement(e);
033: DOM.setElementProperty(e, "type", "hidden");
034: }
035:
036: /**
037: * Constructor for <code>Hidden</code>.
038: *
039: * @param name name of the hidden field
040: */
041: public Hidden(String name) {
042: this ();
043: setName(name);
044: }
045:
046: /**
047: * Constructor for <code>Hidden</code>.
048: *
049: * @param name name of the hidden field
050: * @param value value of the hidden field
051: */
052: public Hidden(String name, String value) {
053: this (name);
054: setValue(value);
055: }
056:
057: /**
058: * Gets the default value of the hidden field.
059: *
060: * @return the default value
061: */
062: public String getDefaultValue() {
063: return DOM.getElementProperty(getElement(), "defaultValue");
064: }
065:
066: /**
067: * Gets the id of the hidden field.
068: *
069: * @return the id
070: */
071: public String getID() {
072: return DOM.getElementProperty(getElement(), "id");
073: }
074:
075: /**
076: * Gets the name of the hidden field.
077: *
078: * @return the name
079: */
080:
081: public String getName() {
082: return DOM.getElementProperty(getElement(), "name");
083: }
084:
085: /**
086: * Gets the value of the hidden field.
087: *
088: * @return the value
089: */
090: public String getValue() {
091: return DOM.getElementProperty(getElement(), "value");
092: }
093:
094: /**
095: * Sets the default value of the hidden field.
096: *
097: * @param defaultValue default value to set
098: */
099: public void setDefaultValue(String defaultValue) {
100: DOM.setElementProperty(getElement(), "defaultValue",
101: defaultValue);
102: }
103:
104: /**
105: * Sets the id of the hidden field.
106: *
107: * @param id id to set
108: */
109: public void setID(String id) {
110: DOM.setElementProperty(getElement(), "id", id);
111: }
112:
113: /**
114: * Sets the name of the hidden field.
115: *
116: * @param name name of the field
117: */
118: public void setName(String name) {
119: if (name == null) {
120: throw new NullPointerException("Name cannot be null");
121: } else if (name.equals("")) {
122: throw new IllegalArgumentException(
123: "Name cannot be an empty string.");
124: }
125: DOM.setElementProperty(getElement(), "name", name);
126: }
127:
128: /**
129: * Sets the value of the hidden field.
130: *
131: * @param value value to set
132: */
133: public void setValue(String value) {
134: DOM.setElementProperty(getElement(), "value", value);
135: }
136: }
|