001: /*
002: * $Id: TextField.java 497654 2007-01-19 00:21:57Z rgielen $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts2.views.annotations.StrutsTag;
027: import org.apache.struts2.views.annotations.StrutsTagAttribute;
028:
029: import com.opensymphony.xwork2.util.ValueStack;
030:
031: /**
032: * <!-- START SNIPPET: javadoc -->
033: * Render an HTML input field of type text</p>
034: * <!-- END SNIPPET: javadoc -->
035: *
036: * <p/> <b>Examples</b>
037: * <p/>
038: * <!-- START SNIPPET: exdescription -->
039: * In this example, a text control for the "user" property is rendered. The label is also retrieved from a ResourceBundle via the key attribute.
040: * <!-- END SNIPPET: exdescription -->
041: * <pre>
042: * <!-- START SNIPPET: example -->
043: * <s:textfield key="user" />
044: * <!-- END SNIPPET: example -->
045: * </pre>
046: *
047: * <pre>
048: * <!-- START SNIPPET: example2 -->
049: * <s:textfield name="user" label="User Name" />
050: * <!-- END SNIPPET: example -->
051: * </pre>
052:
053: */
054: @StrutsTag(name="textfield",tldTagClass="org.apache.struts2.views.jsp.ui.TextFieldTag",description="Render an HTML input field of type text")
055: public class TextField extends UIBean {
056: /**
057: * The name of the default template for the TextFieldTag
058: */
059: final public static String TEMPLATE = "text";
060:
061: protected String maxlength;
062: protected String readonly;
063: protected String size;
064:
065: public TextField(ValueStack stack, HttpServletRequest request,
066: HttpServletResponse response) {
067: super (stack, request, response);
068: }
069:
070: protected String getDefaultTemplate() {
071: return TEMPLATE;
072: }
073:
074: protected void evaluateExtraParams() {
075: super .evaluateExtraParams();
076:
077: if (size != null) {
078: addParameter("size", findString(size));
079: }
080:
081: if (maxlength != null) {
082: addParameter("maxlength", findString(maxlength));
083: }
084:
085: if (readonly != null) {
086: addParameter("readonly", findValue(readonly, Boolean.class));
087: }
088: }
089:
090: @StrutsTagAttribute(description="HTML maxlength attribute",type="Integer")
091: public void setMaxlength(String maxlength) {
092: this .maxlength = maxlength;
093: }
094:
095: @StrutsTagAttribute(description="Deprecated. Use maxlength instead.",type="Integer")
096: public void setMaxLength(String maxlength) {
097: this .maxlength = maxlength;
098: }
099:
100: @StrutsTagAttribute(description="Whether the input is readonly",type="Boolean",defaultValue="false")
101: public void setReadonly(String readonly) {
102: this .readonly = readonly;
103: }
104:
105: @StrutsTagAttribute(description="HTML size attribute",type="Integer")
106: public void setSize(String size) {
107: this.size = size;
108: }
109: }
|