@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
super.encodeEnd(context, component);
AbstractAjaxStatus ajaxStatus = (AbstractAjaxStatus) component;
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HtmlConstants.SPAN_ELEM, component);
String clientId = component.getClientId(context);
writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, clientId, "id");
for (StatusState state : StatusState.values()) {
encodeState(context, ajaxStatus, state);
}
writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
writer.writeAttribute(HtmlConstants.TYPE_ATTR, HtmlConstants.TEXT_JAVASCRIPT_TYPE, null);
JSFunction statusConstructor = new JSFunction("new RichFaces.ui.Status", clientId);
Map<String, Object> options = new HashMap<String, Object>();
Map<String, Object> attributes = ajaxStatus.getAttributes();
for (String eventName : EVENT_NAMES) {
String eventAttribute = "on" + eventName;
HandlersChain handlersChain = new HandlersChain(context, component, true);
handlersChain.addInlineHandlerFromAttribute(eventAttribute);
handlersChain.addBehaviors(eventName);