resource = getResource("images/spacer.gif").getUri(
context, menuItem);
}
variables.setVariable("icon", resource);
RendererUtils rendererUtils = getUtils();
if (menuItem.isDisabled()) {
variables.setVariable("iconDisabledClasses",
"rich-menu-item-icon-disabled");
} else {
Map<String, Object> menuItemAttributes = menuItem.getAttributes();
// create attributes string for item without parent
Map<String, Object> attrMap = new HashMap<String, Object>(3);
if (!isNestedInMenu(menuItem)) {
rendererUtils.addToScriptHash(attrMap, "styleClass", menuItemAttributes.get(HTML.STYLE_CLASS_ATTR),
null, ScriptHashVariableWrapper.DEFAULT);
rendererUtils.addToScriptHash(attrMap, "onselect", menuItemAttributes.get(HTML.onselect_ATTRIBUTE),
null, ScriptHashVariableWrapper.EVENT_HANDLER);
}
//-----------------------------------
StringBuilder scriptValue = new StringBuilder();
String mode = resolveSubmitMode(menuItem);
if (MenuComponent.MODE_AJAX.equalsIgnoreCase(mode)) {
scriptValue.append("RichFaces.Menu.updateItem(event,this");
if (!attrMap.isEmpty()) {
scriptValue.append(',');
scriptValue.append(ScriptUtils.toScript(attrMap));
}
scriptValue.append(");");
String event = null;
Object onclick = menuItemAttributes.get(HTML.onclick_ATTRIBUTE);
if(onclick != null && onclick.toString().length()>0){
event = HTML.onclick_ATTRIBUTE;
}else{
Object onselect = menuItemAttributes.get(HTML.onselect_ATTRIBUTE);
if(onselect != null && onselect.toString().length()>0){
event = HTML.onselect_ATTRIBUTE;
}
}
scriptValue.append(AjaxRendererUtils.buildOnEvent(
menuItem, context, event, true).toString());
menuItemAttributes.put(HTML.onselect_ATTRIBUTE, null);
} else if (MenuComponent.MODE_SERVER.equalsIgnoreCase(mode)) {
/*
String id = menuItem.getClientId(context);
scriptValue.append("var form=A4J.findForm(this);");
scriptValue.append("var params={");
scriptValue.append(ScriptUtils.toScript(id + ":hidden"));
scriptValue.append(":");
scriptValue.append(ScriptUtils.toScript(id));
scriptValue.append("};");
List params = encodeParams(context, menuItem);
if(!params.isEmpty()){
for (Iterator iterator = params.iterator(); iterator.hasNext();) {
scriptValue.append(iterator.next());
}
}
scriptValue.append("Richfaces.jsFormSubmit(");
scriptValue.append(ScriptUtils.toScript(id)).append(",");
scriptValue.append("form.id").append(",");
Object target = menuItem.getAttributes().get("target");
if (null != target) {
scriptValue.append(ScriptUtils.toScript(target));
} else {
scriptValue.append("''");
}
scriptValue.append(",");
scriptValue.append("params);return false;");
*/
Object onclick = menuItemAttributes.get(HTML.onclick_ATTRIBUTE);
if(onclick != null && onclick.toString().length()>0){
scriptValue.append(onclick.toString());
scriptValue.append(";");
}
scriptValue.append("RichFaces.Menu.submitForm(event,this");
Map<String, Object> scriptOptionsMap = new HashMap<String, Object>(5);
rendererUtils.addToScriptHash(scriptOptionsMap, "a", attrMap, null, ScriptHashVariableWrapper.DEFAULT);
Map<String, Object> paramsMap = getParamsAsMap(context, menuItem);
rendererUtils.addToScriptHash(scriptOptionsMap, "p", paramsMap, null, ScriptHashVariableWrapper.DEFAULT);
String target = (String) menuItemAttributes.get("target");
rendererUtils.addToScriptHash(scriptOptionsMap, "t", target, null, ScriptHashVariableWrapper.DEFAULT);
if (!scriptOptionsMap.isEmpty()) {
scriptValue.append(',');
scriptValue.append(ScriptUtils.toScript(scriptOptionsMap));
}