Chinaunix首页 | 论坛 | 博客
  • 博客访问: 543514
  • 博文数量: 855
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-16 19:08
文章分类

全部博文(855)

文章存档

2011年(1)

2008年(854)

我的朋友

分类:

2008-10-16 19:18:18

JSR168规范规定,所有Portlet都必须直接地或者间接地实现Portlet接口。同时,也提供了一个叫GenericPortlet的基类,该类继承了Portlet接口,统一定义了可供 Portal 容器识别和调用的方法。因此,大部分情况下,开发人员只需要继承GenericPortlet这个基类,而不必直接实现Portlet接口。
    Liferay Portal也是一个支持JSR168的企业门户,我们来看看在它的内部,是如何扩展GenericPortlet的。
    1)      它自定义类LiferayPortlet扩展GenericPortlet,增加几个模式,如CONFIG、EDIT_GUEST、EDIT_DEFAULT、PREVIEW、PRINT.
    2)      定义class StrutsPortlet,扩展LiferayPortlet,初始化模式参数,并定义了process action的过程。在liferay中,配置文件portlet-custom.xml中配置各portlet的一些,其中有个很重要的参数是portlet-class,该参数的值一般是com.liferay.portlet.StrutsPortlet,表明该portlet是struts portlet.
    3)      定义类JSPPortlet,扩展LiferayPortlet,该类在liferay中用不上,所以这边不做研究。简单提一下,如果参数portlet-class配置的值是JSPPortlet,那么该portlet是JSPPortlet。
    4)      注意到有个IFramePortlet扩展了StrutsPortlet,大家可能就有疑问了,为什么在liferay中,有那么多的portlet,单单就它需要扩展StrutsPortlet,通过查看该类的源代码:
    view plaincopy to clipboardprint?
    public static final String DEFAULT_EDIT_ACTION = "/iframe/edit";

    public static final String DEFAULT_VIEW_ACTION = "/iframe/view";

    public void init(PortletConfig config) throws PortletException {

        super.init(config);

        if (Validator.isNull(editAction)) {

            editAction = DEFAULT_EDIT_ACTION;

        }

        if (Validator.isNull(viewAction)) {

            viewAction = DEFAULT_VIEW_ACTION;

        }

    }

     public static final String DEFAULT_EDIT_ACTION = "/iframe/edit";

     public static final String DEFAULT_VIEW_ACTION = "/iframe/view";

     public void init(PortletConfig config) throws PortletException {

      super.init(config);

      if (Validator.isNull(editAction)) {

       editAction = DEFAULT_EDIT_ACTION;

      }

      if (Validator.isNull(viewAction)) {

       viewAction = DEFAULT_VIEW_ACTION;

      }

     }可以清楚的知道,IFramePortlet定义自身所需要的default action,当portlet没有配置editAction和viewAction的值时,在代码中赋予默认的值。
    下面图示了这个继承、扩展关系:

【责编:landy】

--------------------next---------------------

阅读(142) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~