Author: pyaschenko
Date: 2009-03-23 05:56:12 -0400 (Mon, 23 Mar 2009)
New Revision: 13088
Modified:
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
trunk/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx
Log:
https://jira.jboss.org/jira/browse/RF-5226
Modified:
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
===================================================================
---
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-03-23
09:49:53 UTC (rev 13087)
+++
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-03-23
09:56:12 UTC (rev 13088)
@@ -33,6 +33,8 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.renderkit.ComponentVariables;
+import org.ajax4jsf.renderkit.ComponentsVariableResolver;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.resource.InternetResource;
@@ -106,15 +108,30 @@
JSFunction function = new JSFunction(".addItem");
function.addParameter(itemId);
ScriptOptions options = new ScriptOptions(kid);
+
options.addEventHandler("onmouseout");
options.addEventHandler("onmouseover");
options.addOption("closeOnClick", new Integer(flcloseonclick));
options.addOption("flagGroup", new Integer(flagGroup));
+
+ options.addOption("styleClass");
+ options.addOption("style");
+ options.addOption("itemClass");
+ options.addOption("itemStyle");
+ options.addOption("disabledItemClass");
+ options.addOption("disabledItemStyle");
+ options.addOption("selectItemClass");
+ options.addOption("labelClass");
+ options.addOption("selectedLabelClass");
+ options.addOption("disabledLabelClass");
+
options.addOption("selectClass");
- options.addOption("style");
options.addOption("selectStyle");
options.addOption("iconClass");
options.addOption("disabled", Boolean.valueOf(disabled));
+
+ options.addEventHandler("onselect");
+
function.addParameter(options);
return function.toScript();
}
Modified:
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
===================================================================
---
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2009-03-23
09:49:53 UTC (rev 13087)
+++
trunk/ui/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java 2009-03-23
09:56:12 UTC (rev 13088)
@@ -36,6 +36,8 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.ComponentVariables;
@@ -107,7 +109,7 @@
UIMenuItem menuItem = component;
List params = new ArrayList();
- StringBuffer buff = new StringBuffer();
+ StringBuffer buff;
List children = menuItem.getChildren();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
@@ -119,6 +121,7 @@
String name = param.getName();
if (name != null) {
+ buff = new StringBuffer();
Object value = param.getValue();
buff.append("params[");
buff.append(ScriptUtils.toScript(name));
@@ -133,6 +136,37 @@
return params;
}
+ public String encodeParamsAsObject(FacesContext context, UIMenuItem component) throws
IOException {
+
+ UIMenuItem menuItem = component;
+ 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 (name != null) {
+ Object value = param.getValue();
+ buff.append(ScriptUtils.toScript(name));
+ buff.append(":");
+ buff.append(ScriptUtils.toScript(value));
+ buff.append(",");
+ }
+ }
+ }
+ if (buff.length()>1) {
+ buff.deleteCharAt(buff.length()-1);
+ buff.append("}");
+ return buff.toString();
+ } else {
+ return null;
+ }
+ }
public void initializeResources(FacesContext context, UIMenuItem menuItem)
throws IOException {
@@ -158,24 +192,23 @@
variables.setVariable("onmouseoverInlineStyles",
processInlineStyles(context, menuItem, true));
+ //-----------------------------------
StringBuffer scriptValue = new StringBuffer();
String mode = resolveSubmitMode(menuItem);
-
+
if (MenuComponent.MODE_AJAX.equalsIgnoreCase(mode)) {
scriptValue.append(AjaxRendererUtils.buildOnClick(
menuItem, context).toString());
} else if (MenuComponent.MODE_SERVER.equalsIgnoreCase(mode)) {
-
+ /*
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("var form=A4J.findForm(this);");
+ scriptValue.append("var params={");
scriptValue.append(ScriptUtils.toScript(id + ":hidden"));
- scriptValue.append("] = ");
+ scriptValue.append(":");
scriptValue.append(ScriptUtils.toScript(id));
- scriptValue.append(";");
+ scriptValue.append("};");
List params = encodeParams(context, menuItem);
if(!params.isEmpty()){
@@ -197,14 +230,48 @@
}
scriptValue.append(",");
- scriptValue.append("params);}; return false;");
-
+ scriptValue.append("params);return false;");
+ */
+ scriptValue.append("RichFaces.Menu.submitForm(event,this");
+ String params = encodeParamsAsObject(context, menuItem);
+ if (null!=params) {
+ scriptValue.append(params);
+ }
+ String target = (String) menuItem.getAttributes().get("target");
+ if (null != target && target.length()>0) {
+ scriptValue.append(",");
+ scriptValue.append(ScriptUtils.toScript(target));
+ }
+ StringBuffer attr = new StringBuffer();
+ if (!(menuItem.getParent() instanceof MenuComponent))
+ {
+ String styleClass = (String)
menuItem.getAttributes().get("styleClass");
+ String str = "";
+ attr.append(",{");
+ if (null!=styleClass && styleClass.length()>0) {
+ scriptValue.append("styleClass:");
+ scriptValue.append(ScriptUtils.toScript(styleClass));
+ str = ",";
+ }
+ String onselect = (String)
menuItem.getAttributes().get("onselect");
+ if (null!=onselect && onselect.length()>0) {
+ scriptValue.append(str);
+ scriptValue.append("onselect:function(event){");
+ scriptValue.append(onselect);
+ scriptValue.append("}");
+ }
+ attr.append("}");
+ if (attr.length()>3) scriptValue.append(attr);
+ }
+ scriptValue.append(")");
+
} else {
scriptValue.append(getStringAttributeOrEmptyString(menuItem,
"onclick"));
}
if (resource.length() > 0) {
variables.setVariable("onclick", scriptValue.toString());
}
+ //-------------------------------
}
}
Modified:
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
===================================================================
---
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-03-23
09:49:53 UTC (rev 13087)
+++
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-03-23
09:56:12 UTC (rev 13088)
@@ -1377,7 +1377,7 @@
onclick: function(e){
if (this.options.closeOnClick == 1) {
- var menuLayer = this.menu;
+ var menuLayer = this.menu;
while (menuLayer.level > 0) {
menuLayer =
RichFaces.Menu.Layers.layers[(RichFaces.Menu.Layers.father[menuLayer.id])];
}
@@ -1493,3 +1493,33 @@
}
});
+
+RichFaces.Menu.findMenuItem = function (itemId) {
+ var layer;
+ var menuItem = null;
+ for (var id in RichFaces.Menu.Layers.layers) {
+ layer = RichFaces.Menu.Layers.layers[id];
+ menuItem = layer.items[itemId];
+ if (menuItem) break;
+ }
+ return menuItem;
+}
+
+RichFaces.Menu.submitForm = function (event, element, params, target, attr) {
+ var menuItem = RichFaces.Menu.findMenuItem(element.id);
+ var classes = 'dr-menu-item dr-menu-item-enabled rich-menu-item
rich-menu-item-enabled';
+ if (menuItem) {
+ classes =+ ' '+menuItem.options.styleClass;
+ if (menuItem.options.onselect) menuItem.options.onselect(event);
+ } else if (attr){
+ if (attr.styleClass) classes += ' '+attr.styleClass;
+ if (attr.onselect) attr.onselect(event);
+ }
+ element.className = classes;
+ var form=A4J.findForm(element);
+ if (!params) params={};
+ if (!target) target='';
+ params[element.id+':hidden']=element.id;
+ Richfaces.jsFormSubmit(element.id,form.id,target,params);
+ return false;
+}
Modified: trunk/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx
===================================================================
--- trunk/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx 2009-03-23
09:49:53 UTC (rev 13087)
+++ trunk/ui/menu-components/src/main/templates/org/richfaces/htmlMenuItem.jspx 2009-03-23
09:56:12 UTC (rev 13088)
@@ -45,17 +45,19 @@
<jsp:scriptlet><![CDATA[
} else {
- String onselect = (String) component.getAttributes().get("onselect");
+ /*String onselect = (String) component.getAttributes().get("onselect");
if(null!=onselect&&onselect.length()>0){
onselect = onselect+";";
}else{
onselect="";
- }
- variables.setVariable("onselect",onselect);
+ }
+ variables.setVariable("onselect",onselect);
+ */
]]></jsp:scriptlet>
<div id="#{clientId}"
- class="#{menuItemClass}"
+ class="#{menuItemClass}"
+
onmouseout="if (RichFaces.Menu.isWithin(event, this)) return;
this.className='#{menuItemClass}';
#{onmouseoutInlineStyles}
@@ -65,11 +67,13 @@
#{menuItemHoverClass};
#{onmouseoverInlineStyles}
$('#{clientId}:icon').className='dr-menu-icon dr-menu-icon-selected
rich-menu-item-icon rich-menu-item-icon-selected
#{component.attributes['iconClass']}';
- Element.addClassName($('#{clientId}:anchor'),
'rich-menu-item-label-selected');"
- style="#{menuItemStyle}"
- onclick="this.className='dr-menu-item dr-menu-item-enabled rich-menu-item
rich-menu-item-enabled #{component.attributes['styleClass']}'; #{onselect}
#{onclick};"
+ Element.addClassName($('#{clientId}:anchor'),
'rich-menu-item-label-selected');"
+
onmouseup="Event.stop(event); #{component.attributes['onmouseup']}"
- onmousedown="Event.stop(event);
#{component.attributes['onmousedown']}">
+ onmousedown="Event.stop(event);
#{component.attributes['onmousedown']}"
+ onclick="#{onclick}"
+
+ style="#{menuItemStyle}">
<f:call name="utils.encodeAttributes">
<f:parameter value="onmousemove" />
</f:call>