Входные компоненты отправляют свой идентификатор клиента как имя параметра запроса в случае синхронных запросов и как значение параметра запроса 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;
}