论坛首页 Java企业应用论坛

定制IBM WCM 实现内容的查看次数记录

浏览 2231 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-05-14   最后修改:2009-05-14

思路:

1、在内容项的编写模板中增加查看次数元素即: 编号元素(数字),设置为整数,默认值1,隐藏

2、在展示模板中增加jsp定制元素,实现在每次展示的时候调用jsp元素增加查看次数

jsp定制元素说明:

<%@page session="false" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="javax.portlet.RenderRequest,
	com.ibm.workplace.wcm.api.*,
	com.ibm.workplace.wcm.api.exceptions.*,
	javax.naming.*,
	com.ibm.workplace.wcm.api.custom.*" %>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%
	String texts = "";
	Workspace wsa= null;
try
			{		
								
				InitialContext ctx = new InitialContext();
				WebContentService webContentService = (WebContentService)ctx.lookup("portal:service/wcm/WebContentService");
				wsa = webContentService.getRepository().getWorkspace();
}catch(NamingException ne)
            {
            	System.out.println("[WFACTION] Error occurred. Msg=" + ne.getMessage());
              ne.printStackTrace();
                //return null;
            }
            catch(Exception e)
            {
				System.out.println("[WFACTION] Error occurred. Msg=" + e.getMessage());
                //directive = Directives.ROLLBACK_DOCUMENT;
                //message = e.getMessage();
            }





 
//Get the rendering context
RenderingContext renderingContext = (RenderingContext)
request.getAttribute(Workspace.WCM_RENDERINGCONTEXT_KEY);
 
//Get the current content object
Content current = renderingContext.getContent();

NumericComponent clickNum = (NumericComponent)current.getComponent("clickNum");

clickNum.setNumber( Integer.valueOf( clickNum.getNumber().intValue() +1));
current.setComponent("clickNum", clickNum);
//Save the content
wsa.save(current);

		out.println(clickNum);
%>

 
 

 

代码思路就是获得内容项的点击数元素加1然后再保存回内容项

   发表时间:2009-09-25  
谢谢楼主!!!思路知道了。
那个展示模板中增加jsp定制元素是怎么添加的?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics