/** * Executes a JavaScript statement. * * @param statement the JavaScript statement. */ public void executeScript(String statement) { getRequestContext().getScriptsToExecute().add(statement); }
public static void execute(String javaScript) { // RequestContext.getCurrentInstance().execute(javaScript); RequestContext.getCurrentInstance().getScriptsToExecute().add(javaScript); }
/** * Invoke this method to commit the most recent set of ajax updates and restart the tracking of changes. Use this when you have processes the updates to the * model and are confident that any changes made to this point can be cleared (likely because you have persisted those changes). */ public void commitUpdates() { resetSubmitted(); final FacesContext context = FacesContext.getCurrentInstance(); if (context.getPartialViewContext().isPartialRequest()) { final StringBuilder eval = new StringBuilder(); final String jsVar = resolveWidgetVar(); eval.append("PF('").append(jsVar).append("')").append(".clearDataInput();"); RequestContext.getCurrentInstance().getScriptsToExecute().add(eval.toString()); } }
/** * Adds eval scripts to update the bad data array in the sheet to render validation failures produced by the most recent ajax update attempt. * * @param context the FacesContext */ public void renderBadUpdateScript(final FacesContext context) { final String widgetVar = resolveWidgetVar(); final String invalidValue = getInvalidDataValue(); StringBuilder sb = new StringBuilder("PF('" + widgetVar + "')"); sb.append(".cfg.errors="); sb.append(invalidValue); sb.append(";"); sb.append("PF('" + widgetVar + "')"); sb.append(".ht.render();"); RequestContext.getCurrentInstance().getScriptsToExecute().add(sb.toString()); sb = new StringBuilder(); sb.append("PF('").append(widgetVar).append("')"); sb.append(".sheetDiv.removeClass('ui-state-error')"); if (!getInvalidUpdates().isEmpty()) { sb.append(".addClass('ui-state-error')"); } RequestContext.getCurrentInstance().getScriptsToExecute().add(sb.toString()); }
protected void encodeScripts(RequestContext requestContext) throws IOException { List<String> scripts = requestContext.getScriptsToExecute(); if (!scripts.isEmpty()) { startEval(); for (int i = 0; i < scripts.size(); i++) { getWrapped().write(scripts.get(i)); getWrapped().write(';'); } endEval(); } }
protected void encodeOnloadScripts(ResponseWriter writer) throws IOException { List<String> scripts = RequestContext.getCurrentInstance().getScriptsToExecute(); if (!scripts.isEmpty()) { writer.startElement("script", null); writer.writeAttribute("type", "text/javascript", null); writer.write("$(function(){"); for (int i = 0; i < scripts.size(); i++) { writer.write(scripts.get(i)); writer.write(';'); } writer.write("});"); writer.endElement("script"); } }
RequestContext.getCurrentInstance().getScriptsToExecute().add(eval.toString());