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