gpt4 book ai didi

jsf - 在 PhaseListener 中记录调用的托管 Bean 操作

转载 作者:行者123 更新时间:2023-12-01 18:50:50 27 4
gpt4 key购买 nike

我正在使用 Sun JSF 2.0 并编写了一个扩展 javax.faces.event.PhaseListener 的阶段监听器。我能够记录源 URI、目标 URI、总时间等。但到目前为止,无法记录 ManagedBean 以及在该客户端事件期间调用的相应方法。我怎样才能做到这一点?

最佳答案

输入组件在同步请求的情况下将其客户端 ID 作为请求参数名称发送,并作为请求参数值 javax.faces.source 发送。异步(ajax)请求时的请求参数。只需循环请求参数并检查是否有 UICommand组件可通过 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;
}

关于jsf - 在 PhaseListener 中记录调用的托管 Bean 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4788454/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com