public <T extends UIComponent & Widget> void resolveWidget(String widgetVar, Consumer<T> callback) {
        FacesContext facesContext = getFacesContext();

        SearchExpressionContext context = SearchExpressionContext.createSearchExpressionContext(facesContext,
                facesContext.getViewRoot(),
                EnumSet.of(SearchExpressionHint.RESOLVE_SINGLE_COMPONENT, SearchExpressionHint.SKIP_VIRTUAL_COMPONENTS),
                null);

        facesContext.getApplication().getSearchExpressionHandler().resolveComponent(
                context,
                "@widgetVar(" + widgetVar + ")",
                (ctx, target) -> {
                    callback.accept((T) target);
                });
    }
Search for a {@code Widget} by the given widgetVar and invokes the callback.

@param widgetVar the widgetVar.
@param callback the callback.
@param <T> the type of the widget.
@throws ComponentNotFoundException if the widget can't be found.
primefaces/src/main/java/org/primefaces/PrimeFaces.java