관리 Bean에서 실행 된 작업을 로깅해야합니다.이 링크 Logging the invoked managed bean action in a PhaseListener은 작업과 관련된 문제를 해결하는 데 도움이됩니다. 내가 actionListener
를 사용할 때, 나는호출 된 관리 Bean actionListener를 PhaseListener에 로깅
String methodExpression = component.getActionExpression().getExpressionString();
가 어떻게이 actionListener
메소드의 이름을 얻을 수 NullPointerException
@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;
}
NullPointerException
선 발생이? 나는 당신은 좋은 방법에 있었다
private UICommand findInvokedCommandComponent(FacesContext context) {
UIViewRoot view = context.getViewRoot();
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (context.getPartialViewContext().isAjaxRequest()) {
UIComponent component = view.findComponent(params.get("javax.faces.source"));
if (component instanceof UICommand) {
// component.get
UICommand comp= (UICommand) component;
ActionListener[] actionListeners= comp.getActionListeners();
System.out.println("Taille des Listeners : "+actionListeners.length);
ActionListener method;
method = actionListeners[0];
String toString = method.toString();
System.out.println("ActionListener : "+toString);
return (UICommand) component;
}
} else {
for (String clientId : params.keySet()) {
UIComponent component = view.findComponent(clientId);
if (component instanceof UICommand) {
return (UICommand) component;
}
}
}
return null;
}
System.out.println("ActionListener : "+toString); returns ActionListener : `[email protected]` . What I would like to have is `#{bean.action}` .Maybe I did it the wrong way
덕분에 당신의 인내 :) 당신의 도움으로 해결 – bouikstefan
@bouikstefan 그것은 당신의 질문에 적절하게 답변한다면 그것을 받아 들여야합니다! –