`

笨点子:根据不同分类生成多个Portlet实例

阅读更多

     客户需求:客户有多个不同的分类,包括新闻,论坛,博客,微博,视频,报刊,来自同一个数据源。
     客户想要的功能,完成一个portlet的开发,可以预先设置不同的分类项,而表现出不同的输出结果。
     需求延伸:二维度的分类需求,比如针对张三的新闻,李四的论坛等等。如下所示:

监测项 新闻 论坛 博客 微博 视频 报刊
张三
李四
...

 

 

      开发设计:在对应的数据库设计表:PortletMapping

column Name column Key DataType
id id Integer
监测项,如张三李四 monitorId Integer
数据类型,新闻,论坛... dataType Integer
Portlet 实例化 windowId,唯一Id windowId Integer

      如上所述,基本的技术实现方式就是要portlet根据不同的getWindowID生成不同的绑定分项。

 

 

技术实现代码,portlet.xml当中加入:

<portlet>
		<portlet-name>testPorlect</portlet-name>
		<portlet-class>com.antbee.base.TestPortlet</portlet-class>
		<expiration-cache>1000</expiration-cache>
		<cache-scope>private</cache-scope>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<portlet-mode>edit</portlet-mode>						
		</supports>
		<resource-bundle>content.Language-ext</resource-bundle>
		<portlet-info>
			<title>ohh,This is a test only.</title>
		</portlet-info>
	</portlet>

 实现方式TestPortlet.java,Action片段:

@ProcessAction(name = "markForWindowAction")
	public void bindWindowId(ActionRequest request, ActionResponse response) throws PortletException, IOException {		
		String monitorItem = request.getParameter("monitorItem");
		String dataType = request.getParameter("dataType");		
		String windowId = request.getWindowID();
		 //此处代码省略,基本思路
                //根据windowId,检查对应的表当中有没有数据
               //如果有数据,重新绑定monitorItem和dataType,
               //如果没有数据,就生成一个新的记录,绑定monitorItem,dataType,windowId.
              //保存更新记录
response.encodeURL(Constants.PATH_TO_JSP_CONCERNEDDOCS_PAGE + Constants.EDIT_PAGE)).include(
					request, response);
		}
	}

 实现方式TestPortlet.java,doView片段:

@RenderMode(name = "VIEW")
	public void view(RenderRequest request, RenderResponse response) throws PortletException, IOException {		
		String windowId = request.getWindowID();
		//同样代码省略,基本思路如下:
               //根据windowId,取得绑定的数据
              //如果没有绑定数据,则输出提示。
              //如果有绑定数据,则根据绑定数据从数据库取出要展示的数据。
             //输出展示数据或者提示。
		getPortletContext().getRequestDispatcher(
				response.encodeURL(Constants.PATH_TO_JSP_CONCERNEDDOCS_PAGE + Constants.HOME_PAGE)).include(request,
				response);
	}
 

   当然了,这是一个比较笨的方法,大家有没有更好的办法了呀?

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics