writer.write(var + ".addItems([");
for(UIComponent child : menu.getChildren()) {
if(child instanceof MenuItem && child.isRendered()) {
MenuItem item = (MenuItem) child;
String menuItemClientId = item.getClientId(facesContext);
String onclick = item.getOnclick();
if(!firstMenuitem)
writer.write(",");
else
firstMenuitem = false;
writer.write("{");
writer.write("text:'" + (String) item.getValue() + "'");
if(item.getUrl() != null) {
writer.write(",url:'" + getResourceURL(facesContext, item.getUrl() + "'"));
if(item.getTarget() != null) writer.write(",target:'"+ item.getTarget() + "'");
if(onclick != null) writer.write(",onclick:{fn:function() {" + onclick + "}}");
} else {
String command = item.isAjax() ? buildAjaxRequest(facesContext, item, formClientId, menuItemClientId) : buildNonAjaxRequest(facesContext, item, formClientId, menuItemClientId);
command = onclick == null ? command : onclick + ";" + command;
writer.write(",onclick:{fn: function() {" + command + "}}");
}