<portlet开发指南>第十章

、 Portlet Context

Portlet context与servlet context在概念上是一致的,都是用来存储、获取portlet全局context的对象。

Portlet Context范围

Portlet容器中每一个实例化的portlet都只有一个portletcontext实例,如果部署在分布式环境中没有jvm都会有一个。

Portlet Context 功能

Portletcontext的作用于servletcontext一致,Portletcontext在所在portlet的实例是全局的,用户可以通过调用api来从Portletcontext存放属性和取回属性,也可以通过Portletcontext来初始化一些参数,获取一个到servlet和jsp的分发器(dispatcher)。

与 Servlet Context关系

一个portlet application是普通的web application的扩展版本,所以portlet application同样具有servlet context,可以说Portletcontext的实现上使用了大量servlet context的功能,但是需要强调的是两个对象是完全不同的两个对象。

Context范围的初始化参数,对portlet context和servlet context来说都是一样的,都是在web.xml中定义。

ServletContext 与 PortletContext 协作

Portletcontext与servlet context有同样的方法

Ø getAttribute

Ø getAttributeNames,

Ø getInitParameter

Ø getInitParameterNames

Ø getMimeType,

Ø getRealPath,

Ø getResource,

Ø getResourcePaths,

Ø getResourceAsStream,

Ø log,

Ø removeAttribute

Ø setAttribute.

Portlet 容器运行时

Portlet可以在portlet.xml中定义portlet application级别和具体某个portlet级别的运行时选项。Portlet application级别的运行时选项对所有portlet都有效,具体某个portlet级别的运行时参数只对所定义的portlet有效,并且可以覆盖key一样的参数。

可以通过PortletContext接口的getContainerRuntimeOptions方法来获取运行时参数

Enumeration containerRuntime = this.getPortletContext().getContainerRuntimeOptions();

while (containerRuntime.hasMoreElements()) {

log.info(containerRuntime.nextElement().toString());

}

一般情况来说这些运行时参数是为了版本兼容性、container的个性化设置,但是这些个性化的设置一般是不为推荐的。所有一般情况不需要设置。

posted on 2010-12-20 18:07  sealhui  阅读(1626)  评论(0)    收藏  举报