2011-01-24 64 views
3

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

+0

注意。 – BalusC 2011-01-24 23:43:47

回答

11

输入部件发送他们的客户端ID作为请求参数的名称在同步请求的情况下和作为javax.faces.source请求参数的请求参数值(AJAX)请求的异步情况。只需循环请求参数,并根据此信息检查UICommand组件是否可由UIViewRoot#findComponent()解决,然后进行相应处理。

开球例如:Sun公司已经接管了甲骨文在一年前

@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; 
} 
+0

它的工作......谢谢 – Hussain 2011-01-25 01:38:21