private void listenOnEndAttribute() throws IOException {

        if (lastElement == null) {
            return;
        }

        // no nonce written -> do it if the CSP policy is not provided
        if (Boolean.FALSE.equals(policyProvided.get())) {
            if ("script".equalsIgnoreCase(lastElement) && LangUtils.isBlank(lastNonce)) {
                getWrapped().writeAttribute("nonce", cspState.getNonce(), null);
            }
        }

        if (lastEvents != null && !lastEvents.isEmpty()) {
            String id = lastId;

            // no id written -> generate a new one and write it
            // otherwise we can't identify the element for our scripts
            if (LangUtils.isBlank(id)) {
                id = lastElement.toLowerCase() + "-" + UUID.randomUUID();
                getWrapped().writeAttribute("id", id, null);
            }

            // add current collected events to our state
            cspState.getEventHandlers().put(id, lastEvents);
        }

        reset();
    }
Write needed attributes before the starting element will be closed by adding a trailing '>' character when calling e.g.
{@link ResponseWriter#writeText}.
See {@link ResponseWriter#startElement(String, UIComponent)}
primefaces/src/main/java/org/primefaces/csp/CspResponseWriter.java