RendererUtils utils = getUtils();
boolean shouldRenderForm = utils.getNestingForm(context, component) == null;
String rootElementName = shouldRenderForm ? HtmlConstants.DIV_ELEM : HtmlConstants.SPAN_ELEM;
AbstractPoll poll = (AbstractPoll) component;
writer.startElement(rootElementName, component);
writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, "display:none;", null);
utils.encodeId(context, component);
if (shouldRenderForm) {
String clientId = component.getClientId(context) + RendererUtils.DUMMY_FORM_ID;
utils.encodeBeginForm(context, component, writer, clientId);
utils.encodeEndForm(context, writer);
}
// polling script.
writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript", null);
StringBuffer script = new StringBuffer("");
JSFunction function = new JSFunction(AJAX_POLL_FUNCTION);
Map<String, Object> options = new HashMap<String, Object>();
RenderKitUtils.addToScriptHash(options, "interval", poll.getInterval(), "1000");
// RenderKitUtils.addToScriptHash(options, "pollId", component.getClientId(context));
HandlersChain handlersChain = new HandlersChain(context, poll);
handlersChain.addInlineHandlerFromAttribute(AbstractPoll.ON_TIMER);
handlersChain.addBehaviors(AbstractPoll.TIMER);
handlersChain.addAjaxSubmitFunction();
String handler = handlersChain.toScript();
if (handler != null) {
JSFunctionDefinition timerHandler = new JSFunctionDefinition(JSReference.EVENT);
timerHandler.addToBody(handler);
options.put(AbstractPoll.ON_TIMER, timerHandler);
}
if (poll.isEnabled()) {
options.put(ENABLED, true);
}
function.addParameter(component.getClientId(context));
function.addParameter(options);
// function.appendScript(script);