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/** 018Encapsulates a password field. 019*/ 020public final class Password extends MaxSizable 021{ 022boolean remember = false; 023 024/** 025Creates a new password element with the initial value set to 026an empty string. 027**/ 028public Password(String name) 029 { 030 this(name, ""); 031 } 032 033/** 034Creates a new password element with the specified initial 035value. Note, in most cases the intial value should be and 036will be an empty string. If the specified value is 037<tt>null</tt>, then the initial value is set to "" (the 038empty string). 039**/ 040public Password(String name, String initialValue) 041 { 042 super(name, initialValue); 043 } 044 045public Field.Type getType() { 046 return Field.Type.PASSWORD; 047 } 048 049public void renderImpl(FormData fd, Writer writer) throws IOException 050 { 051 String value = getRenderValue(fd); 052 053 writer.write("<input type='"); 054 writer.write(getType().toString()); 055 056 writer.write("' name='"); 057 writer.write(name); 058 writer.write("'"); 059 060 if (value != null) { 061 writer.write("' value='"); 062 writer.write(value); 063 writer.write("'"); 064 } 065 066 if (! enabled || ! isEnabled(fd)) { 067 writer.write(" disabled"); 068 } 069 070 if (size > 0) { 071 writer.write(" size='"); 072 writer.write(String.valueOf(size)); 073 writer.write("'"); 074 } 075 076 if (maxlen > 0) { 077 writer.write(" maxlength='"); 078 writer.write(String.valueOf(maxlen)); 079 writer.write("'"); 080 } 081 082 if (renderStyleTag) { 083 writer.write(" style='"); 084 writer.write(styleTag); 085 writer.write("'"); 086 } 087 088 final int arlen = arbitraryString.size(); 089 for (int n = 0; n < arlen; n++) { 090 writer.write(" "); 091 writer.write(arbitraryString.get(n).toString()); 092 } 093 094 writer.write("</input>"); 095 } 096 097} //~class Password