创建自己的portlet

来源:互联网 发布:daas大数据 编辑:程序博客网 时间:2024/06/04 18:12

一、创建portlet class

public class DemoPortlet extends GenericPortlet {    private static final String NORMAL_VIEW = "/demo.jsp";    private static final String MAXIMIZED_VIEW = "/maximized.jsp";    private static final String HELP_VIEW = "/help.jsp";    private PortletRequestDispatcher normalView;    private PortletRequestDispatcher maximizedView;    private PortletRequestDispatcher helpView;    public void doView( RenderRequest request, RenderResponse response )        throws PortletException, IOException {        if( WindowState.MINIMIZED.equals( request.getWindowState() ) ) {            return;        }        if ( WindowState.NORMAL.equals( request.getWindowState() ) ) {            normalView.include( request, response );        } else {            maximizedView.include( request, response );        }    }    protected void doHelp( RenderRequest request, RenderResponse response )        throws PortletException, IOException {        helpView.include( request, response );    }    public void init( PortletConfig config ) throws PortletException {        super.init( config );        normalView = config.getPortletContext().getRequestDispatcher( NORMAL_VIEW );        maximizedView = config.getPortletContext().getRequestDispatcher( MAXIMIZED_VIEW );        helpView = config.getPortletContext().getRequestDispatcher( HELP_VIEW );    }    public void destroy() {        normalView = null;        maximizedView = null;        helpView = null;        super.destroy();    }}
二、创建JSP文件

创建JSP文件:demo.jsp、maximized.jsp、help.jsp,根据你calss类里具体需求具体创建,其中demo.js就是portlet显示的内容,一般情况插件已经生成了三个基本的JSP文件:view.jsp、edit.jsp、help.jsp

三、在portlet.xml里增加自己创建的portlet

<portlet>        <description>This is a demo.</description>        <portlet-name>demoportlet</portlet-name>        <display-name>DemoPortlet Portlet</display-name>        <portlet-class>org.apache.portals.tutorials.DemoPortlet</portlet-class>        <init-param>            <name>ViewPage</name>            <value>/WEB-INF/demo.jsp</value>        </init-param>        <supports>            <mime-type>text/html</mime-type>            <portlet-mode>VIEW</portlet-mode>        </supports>        <supported-locale>en</supported-locale>        <portlet-info>            <title>Demo Portlet</title>            <short-title>Demo Portlet</short-title>            <keywords>demo</keywords>        </portlet-info>    </portlet>

四、在面板新增你创建的portlet会显示



原创粉丝点击