void writeJavascriptHandlers() throws IOException {
        reset();

        if (cspState.getEventHandlers() == null || cspState.getEventHandlers().isEmpty()) {
            return;
        }

        startElement("script", null);
        StringBuilder javascriptBuilder = new StringBuilder(cspState.getEventHandlers().size() * 25);

        for (Map.Entry<String, Map<String, String>> elements : cspState.getEventHandlers().entrySet()) {
            String id = elements.getKey();

            for (Map.Entry<String, String> events : elements.getValue().entrySet()) {
                String event = events.getKey();
                String javascript = events.getValue();

                javascriptBuilder.append("PrimeFaces.csp.register('");
                javascriptBuilder.append(EscapeUtils.forJavaScript(id));
                javascriptBuilder.append("','");
                javascriptBuilder.append(event);
                javascriptBuilder.append("',function(event){");
                javascriptBuilder.append(javascript);
                javascriptBuilder.append("});");
            }
        }

        String javascript = javascriptBuilder.toString();
        writeText(javascript, null);
        endElement("script");

        cspState.getEventHandlers().clear();
    }
Write javascript collected from event/URI handlers to a separate <code>script</code> block.
primefaces/src/main/java/org/primefaces/csp/CspResponseWriter.java