public static <T> T executeInRequestScope(FacesContext context, String var, Object value, Supplier<T> callback) {
        // if no var passed just execute the callback
        if (LangUtils.isBlank(var)) {
            return callback.get();
        }

        Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
        Object oldValue = requestMap.put(var, value);

        try {
            return callback.get();
        }
        finally {
            requestMap.remove(var);
            if (oldValue != null) {
                requestMap.put(var, oldValue);
            }
        }
    }
Executes a callback within the request scope, optionally storing and restoring a value in the FacesContext request map.
If no variable name is provided, the callback is executed without storing or restoring any value.

@param context The FacesContext associated with the current request.
@param var The name of the variable to store in the FacesContext request map.
           If null or empty, the callback is executed without storing or restoring any value.
@param value The value to store in the FacesContext request map under the given variable name. If null, no value is stored.
@param callback A Supplier representing the callback to execute within the request scope.
@return The result of executing the callback.
@param <T> The type of result returned by the callback.
primefaces/src/main/java/org/primefaces/util/ComponentUtils.java