001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.widget;
030:
031: import com.caucho.util.L10N;
032:
033: import java.io.IOException;
034: import java.util.logging.Logger;
035:
036: public class TextWidget extends Widget {
037: private static L10N L = new L10N(TextWidget.class);
038:
039: static protected final Logger log = Logger
040: .getLogger(TextWidget.class.getName());
041:
042: public TextWidget() {
043: }
044:
045: public TextWidget(String id) {
046: super (id);
047: }
048:
049: public TextWidget(Widget parent) {
050: super (parent);
051: }
052:
053: public TextWidget(Widget parent, String id) {
054: super (parent, id);
055: }
056:
057: protected TextWidgetState createState(WidgetConnection connection)
058: throws WidgetException {
059: return new TextWidgetState();
060: }
061:
062: protected boolean isActionParameter(WidgetState state) {
063: return state.getWidgetMode().equals(WidgetMode.EDIT);
064: }
065:
066: public void renderTextHtml(WidgetConnection connection,
067: TextWidgetState widgetState) throws WidgetException,
068: IOException {
069: WidgetMode widgetMode = widgetState.getWidgetMode();
070:
071: if (widgetMode.equals(WidgetMode.HIDDEN)) {
072: return;
073: }
074:
075: WidgetWriter out = connection.getWriter();
076:
077: String value = widgetState.getValue();
078:
079: out.startElement("span");
080:
081: out.writeAttribute("id", getClientId());
082: out.writeAttribute("class", getCssClass());
083:
084: if (widgetState.getWidgetMode().equals(WidgetMode.EDIT)) {
085:
086: out.startElement("input");
087:
088: out.writeAttribute("name", getParameterName());
089:
090: if (value != null)
091: out.writeAttribute("value", value);
092:
093: out.endElement("input");
094: } else {
095: if (value != null)
096: out.writeText(value);
097: }
098:
099: out.endElement("span");
100: }
101: }
|