2011-01-24 14 views
3

私はSun JSF 2.0を使用しており、javax.faces.event.PhaseListenerを拡張したフェーズリスナーを作成しています。私は、ソースURI、ターゲットURI、合計時間などを記録することができます。しかし、これまでManagedBeanと、そのクライアントイベント中に呼び出される対応するメソッドを記録することができませんでした。これどうやってするの?呼び出されたマネージドBeanアクションをPhaseListenerに記録する

+0

注意。 – BalusC

答えて

11

入力コンポーネントは、同期要求の場合は要求パラメータ名として、非同期(ajax)要求の場合は要求パラメータ値javax.faces.source要求パラメータとしてクライアントIDを送信します。リクエストパラメータをループし、この情報に基づいてによってUICommandコンパニオンが解決可能かどうかを確認し、それに応じて処理してください。

キックオフ例:日は一年以上前に、Oracleによって引き継がれている

@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

関連する問題