简单的jetspeed例子实现

一:jetspeed项目的文件的工程描述

mcbeath-jetspeed-pa:编写portlet的子工程

mcbeath-jetspeed-portal:把所有portlet集成的工程

二:一个简单的portlet例子实现

1 新建portlet:   UserPortlet.java

 

package com.mcbeath.portal.portlets;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import javax.portlet.PortletConfig;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;

public class UserPortlet extends GenericPortlet {

    private static final String NORMAL_VIEW = "/user.jsp";
    private static final String MAXIMIZED_VIEW = "/userList.jsp";

    private PortletRequestDispatcher normalView;
    private PortletRequestDispatcher maximizedView;

    public void doView( RenderRequest request, RenderResponse response )
        throws PortletException, IOException {
       //根据前台传过来的状态决定跳转到哪个页面
        if ( WindowState.NORMAL.equals( request.getWindowState() ) ) {
            normalView.include( request, response );
        } else {
            maximizedView.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 );
    }

    public void destroy() {
        normalView = null;
        maximizedView = null;
        super.destroy();
    }
}

2 注册portlet到portlet.xml中

  打开/mcbeath-jetspeed-pa/src/main/webapp/WEB-INF/portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" 
              version="2.0" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
	
    <portlet>
        <description>用户管理</description>
        <portlet-name>UserPortlet</portlet-name>
        <display-name>User Portlet</display-name>
        <portlet-class>com.mcbeath.portal.user.portlets.UserPortlet</portlet-class>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
        <supported-locale>zh</supported-locale>
        <portlet-info>
            <title>用户管理</title>
            <short-title>用户管理</short-title>
            <keywords>用户</keywords>
        </portlet-info>
    </portlet>
</portlet-app>
3 将portlet集成到portal端

   打开/mcbeath-jetspeed-portal/src/main/webapp/WEB-INF/pages/home-page.psml

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<page id="landing"
    xmlns="http://portals.apache.org/jetspeed"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://portals.apache.org/jetspeed http://portals.apache.org/jetspeed-2/2.2/schemas/psml.xsd">
 
    <title>用户管理系统</title>
    
	<fragment id="landing-0" type="layout" name="jetspeed-layouts::VelocityOneColumn">
  		<fragment id="landing-11" type="layout" name="jetspeed-layouts::VelocityOneColumn">
                        <!--此处的名字必须和portlet.xml中的名字一样--> 
                        <fragment id="user" type="portlet" name="mcbeath-jetspeed-pa::UserPortlet" decorator="clear">
	  			<property name="row" value="0" />
	      		        <property name="column" value="0" />
	    	        </fragment>
  		</fragment>
	</fragment>
	<security-constraints>
    	<security-constraints-ref>public-view</security-constraints-ref>
  	</security-constraints>
</page>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值