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 nextapp.echo2.app.Component;
033: import nextapp.echo2.app.PasswordField;
034: import nextapp.echo2.app.TextField;
035: import nextapp.echo2.app.update.ServerComponentUpdate;
036: import nextapp.echo2.webcontainer.ContainerInstance;
037: import nextapp.echo2.webcontainer.DomUpdateSupport;
038: import nextapp.echo2.webcontainer.RenderContext;
039: import nextapp.echo2.webrender.ServerMessage;
040: import nextapp.echo2.webrender.output.CssStyle;
041:
042: import org.w3c.dom.Element;
043: import org.w3c.dom.Node;
044:
045: /**
046: * Synchronization peer for <code>nextapp.echo2.app.TextField</code> components.
047: * <p>
048: * This class should not be extended or used by classes outside of the
049: * Echo framework.
050: */
051: public class TextFieldPeer extends TextComponentPeer implements
052: DomUpdateSupport {
053:
054: /**
055: * @see nextapp.echo2.webcontainer.DomUpdateSupport#renderHtml(nextapp.echo2.webcontainer.RenderContext,
056: * nextapp.echo2.app.update.ServerComponentUpdate, org.w3c.dom.Node, nextapp.echo2.app.Component)
057: */
058: public void renderHtml(RenderContext rc,
059: ServerComponentUpdate addUpdate, Node parentNode,
060: Component component) {
061: TextField textField = (TextField) component;
062: String elementId = ContainerInstance.getElementId(textField);
063:
064: ServerMessage serverMessage = rc.getServerMessage();
065: serverMessage.addLibrary(TEXT_COMPONENT_SERVICE.getId());
066:
067: Element inputElement = parentNode.getOwnerDocument()
068: .createElement("input");
069: inputElement.setAttribute("id", elementId);
070: if (textField instanceof PasswordField) {
071: inputElement.setAttribute("type", "password");
072: } else {
073: inputElement.setAttribute("type", "text");
074: }
075: String value = textField.getText();
076: if (value != null) {
077: inputElement.setAttribute("value", value);
078: }
079:
080: if (textField.isFocusTraversalParticipant()) {
081: inputElement.setAttribute("tabindex", Integer
082: .toString(textField.getFocusTraversalIndex()));
083: } else {
084: inputElement.setAttribute("tabindex", "-1");
085: }
086:
087: String toolTipText = (String) textField
088: .getRenderProperty(TextField.PROPERTY_TOOL_TIP_TEXT);
089: if (toolTipText != null) {
090: inputElement.setAttribute("title", toolTipText);
091: }
092:
093: Integer maximumLength = (Integer) textField
094: .getRenderProperty(TextField.PROPERTY_MAXIMUM_LENGTH);
095: if (maximumLength != null) {
096: inputElement.setAttribute("maxlength", maximumLength
097: .toString());
098: }
099:
100: CssStyle cssStyle = createBaseCssStyle(rc, textField);
101: if (cssStyle.hasAttributes()) {
102: inputElement.setAttribute("style", cssStyle.renderInline());
103: }
104:
105: parentNode.appendChild(inputElement);
106:
107: renderInitDirective(rc, textField);
108: }
109: }
|