Jsf 在PhaseListener中记录调用的托管bean操作
我正在使用Sun JSF 2.0,并编写了一个阶段侦听器,扩展了javax.faces.event.PhaseListener。我能够记录源URI、目标URI、总时间等。但到目前为止,无法记录在该客户端事件期间将调用的ManagedBean和相应方法。如何执行此操作?输入组件在同步请求的情况下将其客户端ID作为请求参数名称发送,在异步(ajax)请求的情况下,将其作为请求参数值Jsf 在PhaseListener中记录调用的托管bean操作,jsf,logging,jsf-2,phaselistener,Jsf,Logging,Jsf 2,Phaselistener,我正在使用Sun JSF 2.0,并编写了一个阶段侦听器,扩展了javax.faces.event.PhaseListener。我能够记录源URI、目标URI、总时间等。但到目前为止,无法记录在该客户端事件期间将调用的ManagedBean和相应方法。如何执行此操作?输入组件在同步请求的情况下将其客户端ID作为请求参数名称发送,在异步(ajax)请求的情况下,将其作为请求参数值javax.faces.source请求参数发送。只需循环遍历请求参数,检查UICommandcomponent是否可由
javax.faces.source
请求参数发送。只需循环遍历请求参数,检查UICommand
component是否可由UIViewRoot\findComponent()
根据此信息解决,然后进行相应处理
启动示例:
@Override
public void beforePhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
if (context.isPostback()) {
UICommand component = findInvokedCommandComponent(context);
if (component != null) {
String methodExpression = component.getActionExpression().getExpressionString();
// It'll contain #{bean.action}.
}
}
}
private UICommand findInvokedCommandComponent(FacesContext context) {
UIViewRoot view = context.getViewRoot();
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (context.getPartialViewContext().isAjaxRequest()) {
return (UICommand) view.findComponent(params.get("javax.faces.source"));
} else {
for (String clientId : params.keySet()) {
UIComponent component = view.findComponent(clientId);
if (component instanceof UICommand) {
return (UICommand) component;
}
}
}
return null;
}
@覆盖
前期公共无效(阶段事件事件){
FacesContext context=event.getFacesContext();
if(context.isPostback()){
UICommand组件=FindInvokedCommand组件(上下文);
如果(组件!=null){
String methodExpression=component.getActionExpression().getExpressionString();
//它将包含#{bean.action}。
}
}
}
专用UICommand FindInVokedCommand组件(FacesContext上下文){
UIViewRoot视图=context.getViewRoot();
Map params=context.getExternalContext().getRequestParameterMap();
if(context.getPartialViewContext().isAjaxRequest()){
return(UICommand)view.findComponent(params.get(“javax.faces.source”);
}否则{
for(字符串clientId:params.keySet()){
UIComponent=view.findComponent(clientId);
if(UICommand的组件实例){
返回(UICommand)组件;
}
}
}
返回null;
}
请注意,Sun已在一年多前被Oracle接管。