簡體   English   中英

在PhaseListener中記錄調用的托管bean操作

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM