conditionaltag.java

来自「OA典型例子」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * $Id: ConditionalTag.java,v 1.2 2001/10/18 00:46:06 ro89390 Exp $
 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
 */

package com.sure.taglibs.smart;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import java.util.Collection;

/**
 * A conditional tag.
 *
 * <waf:conditional id="id" scope="scope">
 *   <waf:true>blah</waf:true>
 *   <waf:false>blah</waf:false>
 * </waf:conditional>
 */
public class ConditionalTag extends BodyTagSupport {

    boolean value;

    String id;
    String scope;

    public void setId(String i) { id = i; }

    public void setScope(String s) { scope = s; }

    public boolean getValue() { return value; }

    public int doStartTag() throws JspTagException {
        Object o = null;

        if (scope.equals("request")) {
            o = pageContext.getRequest().getAttribute(id);
        }
        else if (scope.equals("session")) {
            o = pageContext.getSession().getAttribute(id);
        }
        else if (scope.equals("page")) {
            o = pageContext.getAttribute(id);
        }

        value = doTest(o);

        return EVAL_BODY_INCLUDE;
    }

    protected boolean doTest(Object o) throws JspTagException {
        return false;
    }

    public int doEndTag() throws JspTagException { return EVAL_PAGE; }
}

⌨️ 快捷键说明

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