textareatag.java

来自「一个专门用来快速开发网站的框架」· Java 代码 · 共 129 行

JAVA
129
字号
package com.core.taglib;

import org.apache.commons.logging.*;
import com.opensymphony.webwork.views.jsp.*;

public class TextAreaTag extends BaseTag {
    private static Log log = LogFactory.getLog(TextAreaTag.class);

    protected String maxlength;
    protected String minlength;
    protected String cols;
    protected String rows;
    protected String wrap;
    protected boolean readonly = false;

    public TextAreaTag() {
    }

    public int doStartTag() throws javax.servlet.jsp.JspException {
        return SKIP_BODY;
    }

    public int doEndTag() throws javax.servlet.jsp.JspException {
        try {
            pageContext.getOut().print(getHtmlStr());
        } catch (Exception e) {
            throw new javax.servlet.jsp.JspException(e);
        }
        return EVAL_BODY_INCLUDE;
    }

    //得到独特属性的字符串
    public String getSelfStr() {
        StringBuffer bufSelf = new StringBuffer();

        if (getMaxlength() != null && !getMaxlength().equals("")) {
            bufSelf.append(" maxlength=\"" + getMaxlength() + "\"");
        }

        if (getMinlength() != null && !getMinlength().equals("")) {
            bufSelf.append(" minlength=\"" + getMinlength() + "\"");
        }

        if (this.getRows() != null && !this.getRows().equals("")) {
            bufSelf.append(" rows=\"" + this.getRows() + "\"");
        }

        if (this.getCols() != null && !this.getCols().equals("")) {
            bufSelf.append(" cols=\"" + this.getCols() + "\"");
        }

        if (isReadonly()) {
            bufSelf.append(" readonly ");
        }

        if (this.getWrap() != null && !this.getWrap().equals("")) {
            bufSelf.append(" wrap=\"" + this.getWrap() + "\"");
        }

        return bufSelf.toString();
    }

    //得到最终的字符串
    public String getHtmlStr() {
        String ret = "";
        // 两种情况都相同的部分
        String strComm = super.getCommHtml() + this.getSelfStr();
        // 检查OgnlValueStack是否有值。
        Object stackObject = TagUtils.getStack(this.pageContext).findValue(name);
        String value = "";
        if (null != stackObject) {
            value = stackObject.toString();
//            log.info("在OgnlValueStack找到了" + name + "! 它的值是:" + value);
        }
        ret = "<textarea " + strComm + ">" + value + "</textarea>";

        return ret;
    }

    public String getCols() {
        return cols;
    }

    public String getRows() {
        return rows;
    }

    public boolean isReadonly() {
        return readonly;
    }

    public String getWrap() {
        return wrap;
    }

    public String getMinlength() {
        return minlength;
    }

    public String getMaxlength() {
        return maxlength;
    }

    public void setCols(String cols) {
        this.cols = cols;
    }

    public void setRows(String rows) {
        this.rows = rows;
    }

    public void setWrap(String wrap) {
        this.wrap = wrap;
    }

    public void setReadonly(boolean readonly) {
        this.readonly = readonly;
    }

    public void setMaxlength(String maxlength) {
        this.maxlength = maxlength;
    }

    public void setMinlength(String minlength) {
        this.minlength = minlength;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?