SimpleTagSupport (Java EE 5)

Java EE API


javax.servlet.jsp.tagext Class SimpleTagSupport

java.lang.Object
  extended by javax.servlet.jsp.tagext.SimpleTagSupport
All Implemented Interfaces:
JspTag, SimpleTag

public class SimpleTagSupport
extends Object
implements SimpleTag

Implements: SimpleTag

用来定义实现 SimpleTag 的标记处理程序的基类。

SimpleTagSupport 类是一个实用工具类,旨在用作新简单标记处理程序的基类。SimpleTagSupport 类实现 SimpleTag 接口,并添加了其他便捷方法,包括用于 SimpleTag 中属性的 getter 方法。

英文文档:

A base class for defining tag handlers implementing SimpleTag.

The SimpleTagSupport class is a utility class intended to be used as the base class for new simple tag handlers. The SimpleTagSupport class implements the SimpleTag interface and adds additional convenience methods including getter methods for the properties in SimpleTag.

Since:
JSP 2.0

Constructor Summary
 
Method Summary
 void
static JspTag
protected  JspFragment
protected  JspContext
 JspTag
 void
 void
 void
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public SimpleTagSupport()
唯一的构造方法。(由子类构造方法调用,通常是隐式的)。
英文文档:

SimpleTagSupport

public SimpleTagSupport()
Sole constructor. (For invocation by subclass constructors, typically implicit.)

Method Detail

public void doTag() throws JspException, java.io.IOException
标记的默认处理不执行任何操作。
ThrowsJspException: 子类可以抛出 JspException,指示处理此标记时发生错误。
ThrowsSkipPageException: 如果(直接或间接)调用此标记的页面停止求值。如果调用的经典标记处理程序返回 SKIP_PAGE,或者调用的简单标记处理程序抛出 SkipPageException,或者调用的 JSP 片段抛出 SkipPageException,则标记文件生成的简单标记处理程序必定抛出此异常。
Throwsjava.io.IOException: 如果写入输出流时出现错误,子类可以抛出 IOException
See also doTag()
英文文档:

doTag

public void doTag()
           throws JspException,
                  IOException
Default processing of the tag does nothing.

Specified by:
doTag in interface SimpleTag
Throws:
JspException - Subclasses can throw JspException to indicate an error occurred while processing this tag.
SkipPageException - If the page that (either directly or indirectly) invoked this tag is to cease evaluation. A Simple Tag Handler generated from a tag file must throw this exception if an invoked Classic Tag Handler returned SKIP_PAGE or if an invoked Simple Tag Handler threw SkipPageException or if an invoked Jsp Fragment threw a SkipPageException.
IOException - Subclasses can throw IOException if there was an error writing to the output stream
See Also:
SimpleTag.doTag()

public void setParent(JspTag parent)
为了进行协作,设置此标记的父标记。

仅当此标记调用嵌套在另一个标记调用中时,容器才调用此方法。

parent 封闭此标记的标记

英文文档:

setParent

public void setParent(JspTag parent)
Sets the parent of this tag, for collaboration purposes.

The container invokes this method only if this tag invocation is nested within another tag invocation.

Specified by:
setParent in interface SimpleTag
Parameters:
parent - the tag that encloses this tag

public JspTag getParent()
为了进行协作,返回此标记的父标记。
return 此标记的父标记
英文文档:

getParent

public JspTag getParent()
Returns the parent of this tag, for collaboration purposes.

Specified by:
getParent in interface SimpleTag
Returns:
the parent of this tag

public void setJspContext(JspContext pc)
在私有 jspContext 字段中存储提供的 JSP 上下文。子类可通过 getJspContext() 访问 JspContext
pc 此调用的页面上下文
See also setJspContext
英文文档:

setJspContext

public void setJspContext(JspContext pc)
Stores the provided JSP context in the private jspContext field. Subclasses can access the JspContext via getJspContext().

Specified by:
setJspContext in interface SimpleTag
Parameters:
pc - the page context for this invocation
See Also:
SimpleTag.setJspContext(javax.servlet.jsp.JspContext)

protected JspContext getJspContext()
返回容器通过 setJspContext 传入的页面上下文。
return 此调用的页面上下文
英文文档:

getJspContext

protected JspContext getJspContext()
Returns the page context passed in by the container via setJspContext.

Returns:
the page context for this invocation

public void setJspBody(JspFragment jspBody)
存储提供的 JspFragment。
jspBody 封装此标记正文的片段。如果页面的操作元素为空,则根本不调用此方法。
See also setJspBody
英文文档:

setJspBody

public void setJspBody(JspFragment jspBody)
Stores the provided JspFragment.

Specified by:
setJspBody in interface SimpleTag
Parameters:
jspBody - The fragment encapsulating the body of this tag. If the action element is empty in the page, this method is not called at all.
See Also:
SimpleTag.setJspBody(javax.servlet.jsp.tagext.JspFragment)

protected JspFragment getJspBody()
返回容器通过 setJspBody 传入的正文。
return 封装此标记正文的片段,如果页面的操作元素为空,则返回 null。
英文文档:

getJspBody

protected JspFragment getJspBody()
Returns the body passed in by the container via setJspBody.

Returns:
the fragment encapsulating the body of this tag, or null if the action element is empty in the page.

final public static JspTag findAncestorWithClass(JspTag from, Class<T> klass)
查找最接近给定实例的给定类类型的实例。此方法使用来自 Tag 和/或 SimpleTag 接口的 getParent 方法。此方法用于协调各协作标记。

对于遍历祖先时遇到的每个 TagAdapter 实例,TagAdapter.getAdaptee() 返回的标记处理程序(而不是 TagAdpater 自身)都会与 klass 进行比较。如果标记处理程序匹配,则返回该标记处理程序,而不是返回它的 TagAdapter。

规范的当前版本仅提供一种正式方法指示标记处理程序的 observable 类型:其标记处理程序实现类,在标记元素的标记类子元素中描述。这可以通过一种非正式的方法扩展,即允许标记库作者在描述子元素中指示 observable 类型。该类型应该是标记处理程序实现类的子类型或者是 void 类型。支持特定标记库(比如 JSP 标准标记库)的专门化容器可以利用这一附加限制。

当标记库作者提供有关标记处理程序 observable 类型的信息时,客户端编程代码应该遵守该限制。具体地说,传递给 findAncestorWithClass 的类应该是 observable 类型的子类型。

from 开始查找实例的位置。
klass 将匹配的 JspTag 或接口的子类
return 实现该接口的最接近的祖先,或者指定类的实例

英文文档:

findAncestorWithClass

public static final JspTag findAncestorWithClass(JspTag from,
                                                 Class<?> klass)
Find the instance of a given class type that is closest to a given instance. This method uses the getParent method from the Tag and/or SimpleTag interfaces. This method is used for coordination among cooperating tags.

For every instance of TagAdapter encountered while traversing the ancestors, the tag handler returned by TagAdapter.getAdaptee() - instead of the TagAdpater itself - is compared to klass. If the tag handler matches, it - and not its TagAdapter - is returned.

The current version of the specification only provides one formal way of indicating the observable type of a tag handler: its tag handler implementation class, described in the tag-class subelement of the tag element. This is extended in an informal manner by allowing the tag library author to indicate in the description subelement an observable type. The type should be a subtype of the tag handler implementation class or void. This addititional constraint can be exploited by a specialized container that knows about that specific tag library, as in the case of the JSP standard tag library.

When a tag library author provides information on the observable type of a tag handler, client programmatic code should adhere to that constraint. Specifically, the Class passed to findAncestorWithClass should be a subtype of the observable type.

Parameters:
from - The instance from where to start looking.
klass - The subclass of JspTag or interface to be matched
Returns:
the nearest ancestor that implements the interface or is an instance of the class specified


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!