Author: abelevich
Date: 2007-09-21 09:58:53 -0400 (Fri, 21 Sep 2007)
New Revision: 3046
Modified:
branches/3.1.x/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
Log:
RF-981
Modified:
branches/3.1.x/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
===================================================================
---
branches/3.1.x/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2007-09-21
13:27:14 UTC (rev 3045)
+++
branches/3.1.x/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2007-09-21
13:58:53 UTC (rev 3046)
@@ -21,6 +21,21 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIParameter;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.ComponentVariables;
import org.ajax4jsf.renderkit.ComponentsVariableResolver;
@@ -29,15 +44,7 @@
import org.richfaces.component.util.ViewUtil;
import org.richfaces.renderkit.CompositeRenderer;
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ActionEvent;
-import javax.faces.event.PhaseId;
-import java.io.IOException;
-import java.util.Map;
-
public class MenuItemRendererBase extends CompositeRenderer {
protected Class getComponentClass() {
@@ -77,7 +84,40 @@
}
}
}
-
+ // find and encode UIParameter's components
+ public List encodeParams(FacesContext context, UIMenuItem component) throws
IOException {
+
+ UIMenuItem menuItem = component;
+ List params = new ArrayList();
+ StringBuffer buff = new StringBuffer();
+
+ List children = menuItem.getChildren();
+ for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ UIComponent child = (UIComponent) iterator.next();
+
+ if(child instanceof UIParameter){
+
+ UIParameter param = (UIParameter)child;
+ String name = param.getName();
+
+ if (null == name) {
+ throw new IllegalArgumentException(Messages.getMessage(
+ Messages.UNNAMED_PARAMETER_ERROR, component.getClientId(context)));
+ }
+
+ Object value = param.getValue();
+ buff.append("params[");
+ buff.append(ScriptUtils.toScript(name));
+ buff.append("] = ");
+ buff.append(ScriptUtils.toScript(value));
+ buff.append(";");
+ params.add(buff.toString());
+ }
+ }
+
+ return params;
+ }
+
public void initializeResources(FacesContext context, UIMenuItem menuItem)
throws IOException {
ComponentVariables variables =
@@ -105,39 +145,53 @@
StringBuffer scriptValue = new StringBuffer();
String mode = resolveSubmitMode(menuItem);
+
if (mode.equalsIgnoreCase(MenuComponent.MODE_AJAX)) {
scriptValue.append(AjaxRendererUtils.buildOnClick(
menuItem, context).toString());
} else if (mode.equalsIgnoreCase(MenuComponent.MODE_SERVER)) {
- String id = menuItem.getClientId(context);
+
+
+ String id = menuItem.getClientId(context);
scriptValue.append('{');
scriptValue.append("var form = A4J.findForm(this);");
scriptValue.append("var params = new Object();");
- scriptValue.append("params['");
- scriptValue.append(id + ":hidden");
- scriptValue.append("'] = '");
- scriptValue.append(id);
- scriptValue.append("';");
- scriptValue.append("Richfaces.jsFormSubmit('");
- scriptValue.append(id);
- scriptValue.append("', ");
- scriptValue.append("form.id, ");
- Object target = menuItem.getAttributes().get("target");
- if (null != target) {
- scriptValue.append("'"+(String) target+"', ");
- } else {
- scriptValue.append("'', ");
+ scriptValue.append("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("params);}; return false;");
+
+ 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;");
+
} else {
- scriptValue.append(
- getStringAttributeOrEmptyString(menuItem, "onclick"));
+ scriptValue.append(getStringAttributeOrEmptyString(menuItem,
"onclick"));
}
if (resource.length() > 0) {
variables.setVariable("onclick", scriptValue.toString());
}
variables.setVariable("menuItemLabelClass",
"rich-menu-item-label");
- }
+ }
}
@@ -182,23 +236,27 @@
protected String processInlineStyles(FacesContext context,
UIMenuItem menuItem,
boolean isOnmouseover) {
- StringBuffer buffer = new StringBuffer();
+
+ StringBuffer buffer = new StringBuffer();
Object style = menuItem.getAttributes().get("style");
Object selectStyle = menuItem.getAttributes().get("selectStyle");
+
if (null == selectStyle) {
return "";
}
+
+ buffer.append("$('" + menuItem.getClientId(context) +
"').style.cssText='");
- buffer.append("$('" + menuItem.getClientId(context)
- + "').style.cssText='");
if (null != style) {
- buffer.append(style.toString() + "; ");
- }
+ buffer.append(style.toString() + "; ");
+ }
+
if (isOnmouseover) {
- buffer.append(selectStyle.toString() + ";';");
+ buffer.append(selectStyle.toString() + ";';");
} else {
- buffer.append("';");
+ buffer.append("';");
}
+
return buffer.toString();
}
}
Show replies by date