001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.wml;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/wml/WmlTextEdit.java $
024: //$Author: Dan $
025: //$Revision: 8 $
026: //$Modtime: 6/11/03 4:30p $
027: /////////////////////////
028:
029: import java.util.Hashtable;
030:
031: import com.salmonllc.html.events.ValueChangedEvent;
032:
033: /**
034: * This class is used for text input field.
035: */
036: public class WmlTextEdit extends WmlFormComponent {
037: private int _maxLength = 0;
038: private int _size = 10;
039: private String _format;
040: private boolean _emptyok = false;
041: private int _tabindex = -1;
042: private String _title;
043:
044: /**
045: * Constructs a new WmlTextEdit component.
046: * @param name The name of the component
047: * @param p The page the component will be placed in.
048: */
049: public WmlTextEdit(String name, com.salmonllc.html.HtmlPage p) {
050: super (name, p);
051: }
052:
053: /**
054: *Generates the Html for the component. This method is called by the framework and should not be called directly
055: */
056: public void generateHTML(java.io.PrintWriter p, int rowNo)
057: throws Exception {
058: if (!_visible)
059: return;
060:
061: if (!getEnabled()) {
062: String out = getValue(rowNo, true);
063: if (out != null)
064: out = fixSpecialHTMLCharacters(out);
065: else
066: out = "";
067:
068: // Code added in an attempt to remove unsightly ' ' in the HtmlTelephonecomponent and
069: // HtmlSSNComponent.
070: // The premise is that the ' ' was introduced to provide for the case when the field
071: // is disabled and when the string is empty or null
072: // The IF statement is introduced to do as much without impacting non-null and non-empty strings
073: if ((out == null) || ((out != null) && (out.equals(""))))
074: out += " ";
075:
076: if (_disabledFontStartTag != null)
077: p.print(_disabledFontStartTag + out
078: + _disabledFontEndTag);
079: else
080: p.print(out);
081: return;
082: }
083:
084: String name = getName();
085: if (rowNo > -1)
086: name += "_" + rowNo;
087: String tag = "<input type=\"text\" id=\"" + name + "\" name=\""
088: + name + "\"";
089:
090: if (_maxLength > 0)
091: tag += " maxlength=\"" + _maxLength + "\"";
092:
093: if (_size > 0) {
094: int size = _size;
095: tag += " size=\"" + size + "\"";
096: }
097:
098: String value = getValue(rowNo, true);
099:
100: if (value != null)
101: tag += " value=\"" + fixSpecialHTMLCharacters(value) + "\"";
102:
103: if (_class != null)
104: tag += " class=\"" + _class + "\"";
105:
106: if (_format != null)
107: tag += " format=\"" + _format + "\"";
108:
109: if (_emptyok)
110: tag += " emptyok=\"True\"";
111:
112: if (_tabindex > -1)
113: tag += " tabindex=\"" + _tabindex + "\"";
114:
115: if (_title != null)
116: tag += " title=\"" + _title + "\"";
117:
118: tag += "/>";
119:
120: p.print(tag);
121: }
122:
123: /**
124: * This method gets the maximum length for the text in the component.
125: */
126: public int getMaxLength() {
127: return _maxLength;
128: }
129:
130: /**
131: * This method gets the display size for the component in characters.
132: */
133: public int getSize() {
134: return _size;
135: }
136:
137: /**
138: * This method gets the format mask for the input.
139: */
140: public String getFormat() {
141: return _format;
142: }
143:
144: /**
145: * This method gets the title for the input.
146: */
147: public String getTitle() {
148: return _title;
149: }
150:
151: /**
152: * This method gets the tabindex of the input.
153: */
154: public int getTabIndex() {
155: return _tabindex;
156: }
157:
158: /**
159: * This method gets the emptyok flag of the input.
160: */
161: public boolean getEmptyOk() {
162: return _emptyok;
163: }
164:
165: /**
166: *Processes the submitted parameters. This method is called by the framework and should not be called directly
167: */
168: public boolean processParms(Hashtable parms, int rowNo)
169: throws Exception {
170: if (!getVisible() || !getEnabled())
171: return false;
172:
173: String oldValue = _value;
174:
175: String name = getName();
176: if (rowNo > -1) {
177: // name += "_" + rowNo;
178: if (_dsBuff != null)
179: oldValue = _dsBuff.getFormattedString(rowNo, _dsColNo);
180: } else {
181: if (_dsBuff != null)
182: oldValue = _dsBuff.getFormattedString(_dsColNo);
183: }
184:
185: String val[] = (String[]) parms.get(name);
186:
187: if (val != null) {
188: _value = val[0].trim();
189: if (_value.equals(""))
190: _value = null;
191: } else
192: _value = null;
193: convertValue();
194:
195: if (!valuesEqual(oldValue, _value)) {
196: ValueChangedEvent e = new ValueChangedEvent(getPage(),
197: this , getName(), getName(), oldValue, _value,
198: rowNo, _dsColNo, _dsBuff);
199: addEvent(e);
200: }
201:
202: return false;
203: }
204:
205: /**
206: * This method sets the maximum length for the text in the component.
207: */
208: public void setMaxLength(int maxLength) {
209: _maxLength = maxLength;
210: }
211:
212: /**
213: * This method sets the display size for the component in characters.
214: */
215: public void setSize(int size) {
216: _size = size;
217: }
218:
219: /**
220: * This method sets the property theme for the component.
221: * @param theme The theme to use.
222: */
223:
224: /**
225: * This method sets the format mask for input.
226: */
227: public void setFormat(String format) {
228: _format = format;
229: }
230:
231: /**
232: * This method sets the emptyok flag for input.
233: */
234: public void setEmptyOk(boolean emptyok) {
235: _emptyok = emptyok;
236: }
237:
238: /**
239: * This method sets the tabindex for input.
240: */
241: public void setTabIndex(int tabindex) {
242: _tabindex = tabindex;
243: }
244:
245: /**
246: * This method sets the title for input.
247: */
248: public void setTitle(String title) {
249: _title = title;
250: }
251:
252: /**
253: * This method gets the postfield form of this component.
254: */
255: public String getPostForm() {
256: if (getVisible() && getEnabled())
257: return "<postfield name=\"" + getName() + "\" value=\"$("
258: + getName() + ")\"/>";
259: return "";
260: }
261:
262: }
|