001// Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 
002// The Molly framework is freely distributable under the terms of an
003// MIT-style license. For details, see the molly pages web site at:
004// http://www.mollypages.org/. Use, modify, have fun !
005
006package fc.web.forms;
007
008import javax.servlet.*;
009import javax.servlet.http.*;
010import java.io.*;
011import java.util.*;
012
013import fc.jdbc.*;
014import fc.io.*;
015import fc.util.*;
016
017/** 
018Represents an HTML text field 
019
020@author hursh jain
021**/
022public final class Text extends MaxSizable
023{
024/** 
025Creates a new text element with a initial value of "". 
026**/
027public Text(String name)
028  {
029  this(name, "");
030  }
031  
032/**
033Creates a new text element with the specified initial value.
034If the specified value is <tt>null</tt>, then the initial
035value is set to "" (the empty string).
036**/
037public Text(String name, String value)
038  {
039  super(name, value);
040  }
041  
042public Field.Type getType() {
043  return Field.Type.TEXT;
044  }
045
046public void renderImpl(FormData fd, Writer writer) throws IOException 
047  {
048  String value = getRenderValue(fd);
049  writer.write("<input type='");
050  writer.write(getType().toString());
051  writer.write("' name='");
052  writer.write(name);
053  writer.write("'");
054
055  if (value != null) {
056    writer.write(" value='");
057    writer.write(value);
058    writer.write("'"); 
059    }
060  
061  if (! enabled || ! isEnabled(fd)) {
062    writer.write(" disabled");
063    }
064  
065  if (size > 0) {
066    writer.write(" size='");
067    writer.write(String.valueOf(size));
068    writer.write("'"); 
069    }
070  
071  if (maxlen > 0) {
072    writer.write(" maxlength='");
073    writer.write(String.valueOf(maxlen));
074    writer.write("'"); 
075    }
076    
077  if (renderStyleTag) {
078    writer.write(" style='");
079    writer.write(styleTag);
080    writer.write("'");
081    }
082    
083  final int arlen = arbitraryString.size();
084  for (int n = 0; n < arlen; n++) {
085    writer.write(" ");
086    writer.write(arbitraryString.get(n).toString());
087    }
088
089  writer.write("></input>");
090  }
091                  
092}          //~class Text