001: /*
002: * (C) Copyright 2004 Nabh Information Systems, Inc.
003: *
004: * All copyright notices regarding Nabh's products MUST remain
005: * intact in the scripts and in the outputted HTML.
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package com.nabhinc.portlet.mvcportlet.taglib;
022:
023: import java.io.IOException;
024:
025: import javax.portlet.RenderRequest;
026: import javax.servlet.jsp.JspException;
027: import javax.servlet.jsp.JspWriter;
028:
029: /**
030: * Input element tag.
031: *
032: * @author Padmanabh Dabke
033: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
034: */
035: public class InputTag extends BaseTag {
036: private int itSize = -1;
037: private int itMaxlength = -1;
038: private String itScript = null;
039: private String itType = "text";
040: private String itValue = null;
041: private String itAccept = null;
042: private String itSrc = null;
043: private String itAlign = null;
044: private boolean itChecked = false;
045:
046: public void release() {
047: super .release();
048: itSize = -1;
049: itMaxlength = -1;
050: itScript = null;
051: // Do NOT reset itType since the type is set by the subclasses and
052: // should be the same when the object gets recycled.
053: //itType = "text";
054: itValue = null;
055: itAccept = null;
056: itSrc = null;
057: itAlign = null;
058: itChecked = false;
059:
060: }
061:
062: /**
063: * The "redisplay contents" flag (used only on <code>password</code>).
064: */
065: protected boolean itRedisplay = true;
066:
067: /**
068: * Returns the value of the input tag.
069: * @return
070: */
071: public String getValue() {
072: return itValue;
073: }
074:
075: public void setValue(String val) {
076: itValue = val;
077: }
078:
079: /**
080: * Returns type of input tag. Default type is <code>text</code>
081: * @return
082: */
083: public String getType() {
084: return itType;
085: }
086:
087: /**
088: * Sets the input's type. Default is <code>text</code>
089: * @param type The type of the input, i.e. checkbox, radio, hidden, etc.
090: */
091: public void setType(String type) {
092: itType = type;
093: }
094:
095: /**
096: * @return Returns the maxlength allowed for the tag.
097: */
098: public int getMaxlength() {
099: return itMaxlength;
100: }
101:
102: /**
103: * @param maxlength The maximum length to set.
104: */
105: public void setMaxlength(int maxLength) {
106: this .itMaxlength = maxLength;
107: }
108:
109: /**
110: * @return Returns the script.
111: */
112: public String getScript() {
113: return itScript;
114: }
115:
116: /**
117: * @param script The script to set.
118: */
119: public void setScript(String script) {
120: this .itScript = script;
121: }
122:
123: /**
124: * @return Returns the size.
125: */
126: public int getSize() {
127: return itSize;
128: }
129:
130: /**
131: * @param size The size to set.
132: */
133: public void setSize(int size) {
134: this .itSize = size;
135: }
136:
137: public boolean getRedisplay() {
138: return itRedisplay;
139: }
140:
141: public void setRedisplay(boolean val) {
142: itRedisplay = val;
143: }
144:
145: public String getAccept() {
146: return itAccept;
147: }
148:
149: public void setAccept(String ac) {
150: itAccept = ac;
151: }
152:
153: public String getSrc() {
154: return itSrc;
155: }
156:
157: public void setSrc(String src) {
158: itSrc = src;
159: }
160:
161: public String getAlign() {
162: return itAlign;
163: }
164:
165: public void setAlign(String al) {
166: itAlign = al;
167: }
168:
169: public boolean getChecked() {
170: return itChecked;
171: }
172:
173: public void setChecked(boolean checked) {
174: this .itChecked = checked;
175: }
176:
177: public int doStartTag() throws JspException {
178:
179: try {
180: RenderRequest request = (RenderRequest) pageContext
181: .getRequest().getAttribute("javax.portlet.request");
182: JspWriter out = pageContext.getOut();
183:
184: // Hidden tag should not be emmitted if the field value is null
185: String fieldValue = itValue == null ? getParamValue(request)
186: : itValue;
187: if (itType.equals("hidden") && fieldValue == null)
188: return SKIP_BODY;
189:
190: out.print("<input type=\"");
191: out.print(itType);
192: out.print("\" name=\"");
193: out.print(getName());
194: out.print("\" ");
195:
196: if (itSize > 0) {
197: out.print("size=\"");
198: out.print(itSize);
199: out.print("\" ");
200: }
201:
202: if (itMaxlength > 0) {
203: out.print("maxlength=\"");
204: out.print(itMaxlength);
205: out.print("\" ");
206: }
207:
208: if (btAccesskey != null) {
209: out.print(" accesskey=\"");
210: out.print(btAccesskey);
211: out.print("\"");
212: }
213: if (itAccept != null) {
214: out.print(" accept=\"");
215: out.print(itAccept);
216: out.print("\"");
217: }
218:
219: if (itSrc != null) {
220: out.print(" src=\"");
221: out.print(itSrc);
222: out.print("\"");
223: }
224:
225: if (itAlign != null) {
226: out.print(" align=\"");
227: out.print(itAlign);
228: out.print("\"");
229: }
230:
231: if (itChecked) {
232: out.print(" checked=\"checked\" ");
233: }
234:
235: out.print(prepareEventHandlers());
236: out.print(prepareStyles());
237:
238: doStartTagHelper(request, out);
239: if (itScript != null) {
240: out.print(itScript);
241: out.print(" ");
242: }
243:
244: out.print("/>");
245: } catch (JspException ex) {
246: error("Error in rendering InputTag.", ex);
247: throw ex;
248: } catch (Exception ex) {
249: error("Error in rendering InputTag.", ex);
250: throw new JspException(ex);
251: }
252:
253: return SKIP_BODY;
254: }
255:
256: public void doStartTagHelper(RenderRequest request, JspWriter out)
257: throws JspException, IOException {
258: String fieldValue = itValue == null ? getParamValue(request)
259: : itValue;
260: if (fieldValue != null) {
261: out.print(" value=\"");
262: out.print(fieldValue);
263: out.print("\" ");
264: }
265:
266: }
267:
268: }
|