001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.webcontainer.syncpeer;
031:
032: import org.w3c.dom.Element;
033: import org.w3c.dom.Node;
034:
035: import nextapp.echo2.app.Component;
036: import nextapp.echo2.app.TextArea;
037: import nextapp.echo2.app.update.ServerComponentUpdate;
038: import nextapp.echo2.webcontainer.ContainerInstance;
039: import nextapp.echo2.webcontainer.RenderContext;
040: import nextapp.echo2.webrender.ClientProperties;
041: import nextapp.echo2.webrender.ServerMessage;
042: import nextapp.echo2.webrender.output.CssStyle;
043:
044: /**
045: * Synchronization peer for <code>nextapp.echo2.app.TextArea</code> components.
046: * <p>
047: * This class should not be extended or used by classes outside of the
048: * Echo framework.
049: */
050: public class TextAreaPeer extends TextComponentPeer {
051:
052: /**
053: * @see nextapp.echo2.webcontainer.DomUpdateSupport#renderHtml(nextapp.echo2.webcontainer.RenderContext,
054: * nextapp.echo2.app.update.ServerComponentUpdate, org.w3c.dom.Node, nextapp.echo2.app.Component)
055: */
056: public void renderHtml(RenderContext rc,
057: ServerComponentUpdate addUpdate, Node parentNode,
058: Component component) {
059: TextArea textArea = (TextArea) component;
060: String elementId = ContainerInstance.getElementId(component);
061:
062: ServerMessage serverMessage = rc.getServerMessage();
063: serverMessage.addLibrary(TEXT_COMPONENT_SERVICE.getId());
064:
065: Element textAreaElement = parentNode.getOwnerDocument()
066: .createElement("textarea");
067: textAreaElement.setAttribute("id", elementId);
068:
069: if (textArea.isFocusTraversalParticipant()) {
070: textAreaElement.setAttribute("tabindex", Integer
071: .toString(textArea.getFocusTraversalIndex()));
072: } else {
073: textAreaElement.setAttribute("tabindex", "-1");
074: }
075:
076: String toolTipText = (String) textArea
077: .getRenderProperty(TextArea.PROPERTY_TOOL_TIP_TEXT);
078: if (toolTipText != null) {
079: textAreaElement.setAttribute("title", toolTipText);
080: }
081:
082: String value = textArea.getText();
083: if (value != null) {
084: if (!rc
085: .getContainerInstance()
086: .getClientProperties()
087: .getBoolean(ClientProperties.QUIRK_TEXTAREA_CONTENT)) {
088: textAreaElement.appendChild(rc.getServerMessage()
089: .getDocument().createTextNode(value));
090: }
091: }
092:
093: CssStyle cssStyle = createBaseCssStyle(rc, textArea);
094: if (cssStyle.hasAttributes()) {
095: textAreaElement.setAttribute("style", cssStyle
096: .renderInline());
097: }
098:
099: parentNode.appendChild(textAreaElement);
100:
101: renderInitDirective(rc, textArea);
102: }
103: }
|