![](/img/trans.png)
[英]How to retrieve a session scoped managed bean in a PhaseListener?
[英]Logging the invoked managed bean action in a PhaseListener
我正在使用Sun JSF 2.0并编写了一个扩展javax.faces.event.PhaseListener
的阶段监听器。 我能够记录源URI,目标URI,总时间等。 但到目前为止无法记录ManagedBean以及在该客户端事件期间将调用的相应方法。 我怎样才能做到这一点?
在同步请求的情况下,输入组件将其客户机ID作为请求参数名称发送,在异步(ajax)请求的情况下,作为请求参数的javax.faces.source
请求参数值。 只需循环遍历请求参数,并根据此信息检查UICommand
UIViewRoot#findComponent()
是否可以UICommand
UICommand组件,然后进行相应处理。
开球示例:
@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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.