@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
RemoteCommand command = (RemoteCommand) component;
AjaxSource source = (AjaxSource) command;
String clientId = command.getClientId(context);
String name = resolveName(command, context);
UIComponent form = (UIComponent) ComponentUtils.findParentForm(context, command);
if(form == null) {
throw new FacesException("RemoteCommand '" + name + "'must be inside a form.");
}
AjaxRequestBuilder builder = RequestContext.getCurrentInstance().getAjaxRequestBuilder();
String request = builder.init()
.source(clientId)
.form(form.getClientId(context))
.process(component, source.getProcess())
.update(component, source.getUpdate())
.async(source.isAsync())
.global(source.isGlobal())
.delay(source.getDelay())
.timeout(source.getTimeout())
.partialSubmit(source.isPartialSubmit(), command.isPartialSubmitSet(), command.getPartialSubmitFilter())
.resetValues(source.isResetValues(), source.isResetValuesSet())
.ignoreAutoUpdate(source.isIgnoreAutoUpdate())
.onstart(source.getOnstart())
.onerror(source.getOnerror())
.onsuccess(source.getOnsuccess())
.oncomplete(source.getOncomplete())
.passParams()
.build();
//script
writer.startElement("script", command);