/** * Generates the AU responses that are part of a page rendering. Notice that {@link * #outPageContent} will invoke this method automatically. * * @param directJS whether to generate JS directly. If true, it generates <code>"x,y"</code> where * x and y are assumed to the responses. If false, it generates <code> * <script>zkac(x,y);</script></pre></code> * @since 5.0.2 */ public static final String outResponseJavaScripts(Execution exec, boolean directJS) { final ExecutionCtrl execCtrl = (ExecutionCtrl) exec; final Collection<AuResponse> responses = execCtrl.getResponses(); if (responses == null || responses.isEmpty()) return ""; execCtrl.setResponses(null); final StringBuffer sb = new StringBuffer(256); if (!directJS) sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkac("); for (Iterator<AuResponse> it = responses.iterator(); it.hasNext(); ) { final AuResponse response = it.next(); sb.append('\'').append(response.getCommand()).append("',"); final List<?> encdata = response.getEncodedData(); if (encdata != null) sb.append('\'') .append( Strings.escape( org.zkoss.json.JSONArray.toJSONString(encdata), Strings.ESCAPE_JAVASCRIPT)) .append('\''); else sb.append((String) null); if (it.hasNext()) sb.append(",\n"); } if (!directJS) sb.append(");\n</script>"); return sb.toString(); }