介绍:
应客户对要求,需要对用户在进行对系统操作时的行为进行记录从而了解用户对系统性能及客户本身的各种回馈信息,其主要包括:
1.系统性能:主要通过操作组件花费时间来具体表现。
2.用户行为:主要通过对组件的点击次数,用以回馈用户所关注的内容。步骤:
本文目前主要监控用户对按钮和超链接的行为进行监控,所采用的 技术主要是通过对组件的action组件的监控来实现
1. 定义一个JavaBean 实现ActionListenerImpl接口。本文中所声明的类
public class PortalActionListener extends ActionListenerImpl {
public PortalActionListener() {
super();
}
}
2.Override其 processAction()方法,在其方法体中进行业务逻辑处理
public void processAction(ActionEvent actionEvent) {
Map attributes = actionEvent.getComponent().getAttributes();
Object opTypeCodeObject = attributes.get("OP_TYPE_CODE");
// 没有OP_TYPE_CODE,直接执行父类,表明不监听此组件
if (opTypeCodeObject == null) {
super.processAction(actionEvent);
return;
}//以下为博主所用的逻辑,仅供参考
String opTypeCode = (((String)opTypeCodeObject).trim()).toUpperCase();
Date azclStartTime =
new Date(new Timestamp(System.currentTimeMillis()));
super.processAction(actionEvent);
Date azclEndTime = new Date(new Timestamp(System.currentTimeMillis()));
HttpServletRequest hr =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String webSessionId = hr.getSession().getId();
User user = (User)JSFUtils.getFromSession(User.PORTAL_USER_KEY);
if (user == null) {
User.logOpTime2DB(webSessionId, null, null, opTypeCode,
azclStartTime, azclEndTime);
} else {
if (user.getUserId() != null) {
User.logOpTime2DB(webSessionId, user.getUserType(),
user.getUserId(), opTypeCode, azclStartTime,
azclEndTime);
}else{
User.logOpTime2DB(webSessionId, "CP",
user.getPartId(), opTypeCode, azclStartTime,
azclEndTime);
}
}
}
3.在faces-config.xml中对该类进行配置
<action-listener>azclportal.main.application.PortalActionListener</action-listener>
4.在需要监控的相关组件上添加attribute组件,用来唯一标识当前组件。如图所示:
图1:在需要监控command组件添加attribute组件示意图
5.对于attribute组件的属性配置如图所示
图2:组件attribute属性配置示意图
6.对于attribute组件属性参数说明:
Name:作为后台javaBean获取value的“key”,本文写成“OP_TYPE_CODE”。
Value: 唯一标识组件,按命名规则即:项目名.页面名.组件具体操作名。这个只是唯一标识,可按自己需求
注意:对于添加有showPopupBehavior的组件,由于showPopupBehavior会在组件的action之前被触发,而且其TriggerType属性action会ignore组件的action属 性,所以使用showPopupBehavior的组件,须将showPopupBehavior当中的TriggerType设置成action之外的值,否则组件的action将失效,达不到监控目的。