@Override
    public void addMessage(String clientId, FacesMessage message) {
        super.addMessage(clientId, message);

        if (markInputAsInvalidOnErrorMsg
                && clientId != null
                && message != null
                && FacesMessage.SEVERITY_ERROR.equals(message.getSeverity())) {

            getViewRoot().invokeOnComponent(this, clientId, (context, target) -> {
                if (target instanceof UIInput) {
                    ((UIInput) target).setValid(false);
                }
            });
        }
    }
Custom {@link FacesContextWrapper} to init and release our {@link PrimeRequestContext}.
primefaces/src/main/java/org/primefaces/context/PrimeFacesContext.java