@Override
protected void renderInitializationScript(IHeaderResponse response) {
Collection<? extends T> choices = getModelObject();
if (choices != null && !choices.isEmpty()) {
JsonBuilder selection = new JsonBuilder();
try {
selection.array();
for (T choice : choices) {
selection.object();
getProvider().toJson(choice, selection);
selection.endObject();
}
selection.endArray();
} catch (JSONException e) {
throw new RuntimeException("Error converting model objec to Json", e);
}
response.renderOnDomReadyJavaScript(JQuery.execute("$('#%s').select2('data', %s);", getMarkupId(),
selection.toJson()));
}
}