@Override
public void encodeBegin(FacesContext context) throws IOException {
super.encodeBegin(context);
String onchange = getOnchange();
Script automaticChangeHandler = null;
Iterable<String> render = getRender();
Iterable<String> execute = getExecute();
final Chart chart = (Chart) getParent();
if (render != null || (execute != null && execute.iterator().hasNext())) {
AjaxInitializer initializer = new AjaxInitializer();
JSONObject ajaxParams = initializer.getAjaxParams(context, this);
MethodExpression actionExpression = getActionExpression();
if (actionExpression != null) {
String expr = actionExpression.getExpressionString().trim();
if (!expr.startsWith("#{")) throw new FacesException("<o:selection> action expression is expected to start with #{ symbols: " + expr);
expr = expr.substring(2, expr.length() - 1);
try {
ajaxParams.put("_action", expr);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
automaticChangeHandler = new ScriptBuilder().functionCall("O$._ajaxReload",
initializer.getRenderArray(context, this, render),
ajaxParams).semicolon().append("return false;");
} else {
MethodExpression actionExpression = getActionExpression();
if (actionExpression != null) {
automaticChangeHandler = new ScriptBuilder().functionCall("O$.submitWithParam",
new ScriptBuilder().O$(chart), getActionFieldName(), "true");
}
}
onchange = Rendering.joinScripts(onchange,
automaticChangeHandler != null ? automaticChangeHandler.toString() : null);
ScriptBuilder buf = new ScriptBuilder().initScript(context, chart, "O$.Chart._initSelection", onchange);
Rendering.renderInitScript(context, buf,
Resources.utilJsURL(context),