创建自己的portlet

一、创建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会显示



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值