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

思路:

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然后再保存回内容项

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值