javaScriptWriter.writeCall(null, cmd);
javaScriptWriter.writeMethodCall(cmd);
    private void encodeJsToolItemBegin(UIComponent component,            SelectItem selectItem, boolean hasChild) throws WriterException {        if (selectItem instanceof SelectItemGroup) {            throw new FacesException(                    "Bad ToolItem type. (depth>1, Must be a selectItemGroup !)",                    null);        }        if (selectItem instanceof IVisibleSelectItem) {            IVisibleSelectItem vs = (IVisibleSelectItem) selectItem;            if (vs.isVisible() == false) {                return;            }        }        ToolBarContext toolBarContext = getToolBarContext();        String parentVarId = toolBarContext.peekVarId();        String varId = javaScriptWriter.getJavaScriptRenderContext()                .allocateVarName();        toolBarContext.pushVarId(varId);        String sid = toolBarContext.getComponentClientId(component);        int style = IStyledSelectItem.AS_PUSH_BUTTON;        if (selectItem instanceof IStyledSelectItem) {            style = ((IStyledSelectItem) selectItem).getStyle();        } else if (selectItem instanceof IGroupSelectItem) {            style = IStyledSelectItem.AS_RADIO_BUTTON;        } else if (selectItem instanceof ICheckSelectItem) {            style = IStyledSelectItem.AS_CHECK_BOX;        }        javaScriptWriter.write("var ").write(varId).write('=');        String cmd;        switch (style) {        case IStyledSelectItem.AS_RADIO_BUTTON:            cmd = "f_appendRadioItem";            break;        case IStyledSelectItem.AS_CHECK_BOX:            cmd = "f_appendCheckItem";            break;        default:            cmd = "f_appendItem";        }        javaScriptWriter.writeCall(null, cmd);        javaScriptWriter.write(parentVarId).write(',').writeString(sid);        int pred = 0;        if (style == IStyledSelectItem.AS_RADIO_BUTTON) {            String groupName = ((IGroupSelectItem) selectItem).getGroupName();            if (groupName != null) {                for (; pred > 0; pred--) {                    javaScriptWriter.write(',').writeNull();                }                javaScriptWriter.write(',').writeString(groupName);            } else {                pred++;            }        } else {            pred++;        }        String txt = selectItem.getLabel();        if (txt != null) {            javaScriptWriter.write(',').writeString(txt);        } else {            pred++;        }        IComponentRenderContext componentContext = writer                .getComponentRenderContext();        Object selectItemValue = selectItem.getValue();        String value = convertItemValue(componentContext, selectItemValue);        if (value != null) {            for (; pred > 0; pred--) {                javaScriptWriter.write(',').writeNull();            }            javaScriptWriter.write(',').writeString(value);        } else {            pred++;        }        if (style == IStyledSelectItem.AS_CHECK_BOX                || style == IStyledSelectItem.AS_RADIO_BUTTON) {            if (toolBarContext.isValueSelected(selectItem, selectItemValue)) {                for (; pred > 0; pred--) {                    javaScriptWriter.write(',').writeNull();                }                javaScriptWriter.write(',').writeBoolean(true);            } else {                pred++;            }        } else {            pred++;        }        if (selectItem instanceof IAccessKeySelectItem) {            String key = ((IAccessKeySelectItem) selectItem).getAccessKey();            if (key != null && key.length() > 0) {                for (; pred > 0; pred--) {                    javaScriptWriter.write(',').writeNull();                }                javaScriptWriter.write(',').writeString(key);            } else {                pred++;            }        } else {            pred++;        }        String description = selectItem.getDescription();        if (description != null) {            for (; pred > 0; pred--) {                javaScriptWriter.write(',').writeNull();            }            javaScriptWriter.write(',').writeString(description);        } else {            pred++;        }        boolean disabled = selectItem.isDisabled();        if (disabled) {            for (; pred > 0; pred--) {                javaScriptWriter.write(',').writeNull();            }            javaScriptWriter.write(',').writeBoolean(true);        } else {            pred++;        }        javaScriptWriter.writeln(");");        if (selectItem instanceof IImagesSelectItem) {            IImagesSelectItem iim = (IImagesSelectItem) selectItem;            String imageURL = iim.getImageURL();            String disabledImageURL = iim.getDisabledImageURL();            String hoverImageURL = iim.getHoverImageURL();            String selectedImageURL = iim.getSelectedImageURL();            String originalImageURL = imageURL;            if (imageURL != null) {                imageURL = AbstractCameliaRenderer.rewriteURL(componentContext,                        IURLRewritingProvider.IMAGE_URL_TYPE, "imageURL",                        imageURL, null);            }            if (disabledImageURL != null) {                disabledImageURL = AbstractCameliaRenderer.rewriteURL(                        componentContext, IURLRewritingProvider.IMAGE_URL_TYPE,                        "disabledImageURL", disabledImageURL, originalImageURL);            }            if (hoverImageURL != null) {                hoverImageURL = AbstractCameliaRenderer.rewriteURL(                        componentContext, IURLRewritingProvider.IMAGE_URL_TYPE,                        "hoverImageURL", hoverImageURL, originalImageURL);            }            if (selectedImageURL != null) {                selectedImageURL = AbstractCameliaRenderer.rewriteURL(                        componentContext, IURLRewritingProvider.IMAGE_URL_TYPE,                        "selectedImageURL", selectedImageURL, originalImageURL);            }            if (imageURL != null || disabledImageURL != null                    || hoverImageURL != null || selectedImageURL != null) {                javaScriptWriter.writeCall(null, "_setItemImages").write(varId);                pred = 0;                if (imageURL != null) {                    for (; pred > 0; pred--) {                        javaScriptWriter.write(',').writeNull();                    }                    javaScriptWriter.write(',').writeString(imageURL);                } else {                    pred++;                }                if (disabledImageURL != null) {                    for (; pred > 0; pred--) {                        javaScriptWriter.write(',').writeNull();                    }                    javaScriptWriter.write(',').writeString(disabledImageURL);                } else {                    pred++;                }                if (hoverImageURL != null) {                    for (; pred > 0; pred--) {                        javaScriptWriter.write(',').writeNull();                    }                    javaScriptWriter.write(',').writeString(hoverImageURL);                } else {                    pred++;                }                if (selectedImageURL != null) {                    for (; pred > 0; pred--) {                        javaScriptWriter.write(',').writeNull();                    }                    javaScriptWriter.write(',').writeString(selectedImageURL);                } else {                    pred++;                }                javaScriptWriter.writeln(");");            }        }    }