001: /* Textbox.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: May 25, 2007 9:49:27 AM, Created by henrichen
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019:
020: package org.zkoss.mil;
021:
022: import org.zkoss.mil.impl.InputElement;
023: import org.zkoss.zk.ui.WrongValueException;
024:
025: /**
026: * A generic text box.
027: *
028: * @author henrichen
029: */
030: public class Textbox extends InputElement {
031: private static final long serialVersionUID = 200705251351L;
032: private String _type = "text";
033:
034: public Textbox() {
035: }
036:
037: public Textbox(String value) throws WrongValueException {
038: setValue(value);
039: }
040:
041: public Textbox(String label, String value)
042: throws WrongValueException {
043: setValue(value);
044: }
045:
046: /** Returns the value.
047: * The same as {@link #getText}.
048: * <p>Default: "".
049: * @exception WrongValueException if user entered a wrong value
050: */
051: public String getValue() throws WrongValueException {
052: return getText();
053: }
054:
055: /** Sets the value.
056: *
057: * @param value the value; If null, it is considered as empty.
058: * @exception WrongValueException if value is wrong
059: */
060: public void setValue(String value) throws WrongValueException {
061: setText(value);
062: }
063:
064: //-- super --//
065: /** Coerces the value passed to {@link #setValue}.
066: *
067: * <p>Default: convert null to an empty string.
068: */
069: protected Object coerceFromString(String value)
070: throws WrongValueException {
071: return value != null ? value : "";
072: }
073:
074: /** Coerces the value passed to {@link #setValue}.
075: *
076: * <p>Default: convert null to an empty string.
077: */
078: protected String coerceToString(Object value) {
079: return value != null ? (String) value : "";
080: }
081:
082: /** random text */
083: protected int getInternalType() {
084: return ANY;
085: }
086:
087: /** Returns the type.
088: * <p>Default: text.
089: */
090: public String getType() {
091: return _type;
092: }
093:
094: /** Sets the type.
095: * @param type the type. Acceptable values are "text" and "password".
096: */
097: public void setType(String type) throws WrongValueException {
098: if (!"text".equals(type) && !"password".equals(type))
099: throw new WrongValueException("Illegal type: " + type);
100:
101: if (!_type.equals(type)) {
102: _type = type;
103: smartUpdateConstraints();
104: }
105: }
106: }
|