[richfaces-svn-commits] JBoss Rich Faces SVN: r362 - trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Apr 11 09:38:32 EDT 2007


Author: A.Skokov
Date: 2007-04-11 09:38:31 -0400 (Wed, 11 Apr 2007)
New Revision: 362

Modified:
   trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
Log:
small refactoring

Modified: trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java
===================================================================
--- trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java	2007-04-11 13:35:03 UTC (rev 361)
+++ trunk/richfaces/menu-components/src/main/java/org/richfaces/renderkit/html/MenuItemRendererBase.java	2007-04-11 13:38:31 UTC (rev 362)
@@ -21,167 +21,174 @@
 
 package org.richfaces.renderkit.html;
 
-import java.io.IOException;
-import java.util.Map;
-
-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 org.ajax4jsf.framework.renderer.AjaxRendererUtils;
 import org.ajax4jsf.framework.renderer.ComponentVariables;
 import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
+import org.ajax4jsf.framework.util.command.CommandScriptBuilder;
 import org.richfaces.component.MenuComponent;
 import org.richfaces.component.UIMenuItem;
 import org.richfaces.component.util.ViewUtil;
 import org.richfaces.renderkit.CompositeRenderer;
-import org.ajax4jsf.framework.util.command.CommandScriptBuilder;
 
+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() {
-		return UIMenuItem.class;
-	}
+public class MenuItemRendererBase extends CompositeRenderer {
 
-	public boolean getRendersChildren() {
-		return true;
-	}
-	
-	public void doDecode(FacesContext context, UIComponent component) {
+    protected Class getComponentClass() {
+        return UIMenuItem.class;
+    }
 
-		super.doDecode(context, component);
-		
-		ExternalContext exCtx = context.getExternalContext();
-		Map rqMap = exCtx.getRequestParameterMap();		
-		Object clnId = rqMap.get(component.getClientId(context));
-		if(clnId == null) {
-			clnId = rqMap.get(component.getClientId(context) + ":hidden");
-		}
-		UIMenuItem menuItem = (UIMenuItem)component;
-		if(clnId!=null) {
-			
-			// enqueue event here for this component or for component with Id
-			// taken from forId attribute
-			
-			String mode = menuItem.getMode();
-			if (!MenuComponent.MODE_NONE.equalsIgnoreCase(mode)) {			
-				
-				ActionEvent actionEvent = new ActionEvent(menuItem);
-				if (menuItem.isImmediate()) {					
-					actionEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
-			    } else {
-			    	actionEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
-			    }
-				menuItem.queueEvent(actionEvent);				
-			}
-		}
-	}
-	
-	
-	public void initializeResources(FacesContext context, UIMenuItem menuItem)
-		throws IOException {
-		ComponentVariables variables = ComponentsVariableResolver.getVariables(this, menuItem);
+    public boolean getRendersChildren() {
+        return true;
+    }
 
-		String resource = menuItem.isDisabled() ? ViewUtil.getResourceURL(menuItem.getIconDisabled()) : ViewUtil.getResourceURL(menuItem.getIcon());		
-		if (resource == null) {			
-			resource = (String) getResource( "images/spacer.gif" ).getUri(context, menuItem);
-		}
-		variables.setVariable("icon", resource);		
-		
-		if (menuItem.isDisabled()) {			
-			variables.setVariable("iconDisabledClasses", "dr-menu-icon-disabled rich-menu-item-icon-disabled");
-		} else {
-			
-			variables.setVariable("onmouseoutInlineStyles", processInlineStyles(context, menuItem, false));
-			variables.setVariable("onmouseoverInlineStyles", processInlineStyles(context, menuItem, true));
-			
-			StringBuffer scriptValue = new StringBuffer();			
-			String mode = resolveSubmitMode(menuItem);						
-			if (mode.equalsIgnoreCase(MenuComponent.MODE_AJAX)) {
-				scriptValue.append(AjaxRendererUtils.buildOnClick(menuItem, context).toString());
-				//scriptValue.append("; Exadel.Menu.Layers.shutdown();return false;");
-			} else if (mode.equalsIgnoreCase(MenuComponent.MODE_SERVER)) {				
-				CommandScriptBuilder builder = new CommandScriptBuilder(menuItem);
-				builder.setCheckActionAndListener(true);
-				Object target = menuItem.getAttributes().get("target");
-				if (null != target) {
-					builder.setTarget((String) target);
-				}
-				builder.setUseOriginalOnclick(true);
-				builder.addCodeBefore("Event.stop(event || window.event);");
-				//builder.addCodeAfter("Exadel.Menu.Layers.shutdown();return false;");				
-				String id = menuItem.getClientId(context);
-				builder.addParameter(id + ":hidden", id);				
-				scriptValue.append(builder.toString());
-			} else {
-				scriptValue.append(getStringAttributeOrEmptyString(menuItem, "onclick"));
-			}
-			if (resource.length() > 0) {
-				variables.setVariable("onclick", scriptValue.toString());
-			}
-		}
-		
-	}
-	
-	protected String getStringAttributeOrEmptyString(UIComponent component, String attributeName) {
-		String attributeValue = (String) component.getAttributes().get(attributeName);
-		
-		if (null == attributeValue) {
-			attributeValue = "";
-		}
-		
-		return attributeValue;
-	}
-	
-	protected UIComponent getIconFacet(UIMenuItem menuItem) {
-		UIComponent iconFacet = null;
-		if (menuItem.isDisabled()) {
-			iconFacet = menuItem.getFacet("iconDisabled");				
-		} else {
-			iconFacet = menuItem.getFacet("icon");
-		}
-		return iconFacet;
-	}
-	
-	protected String resolveSubmitMode(UIMenuItem menuItem) {		
-		String submitMode = menuItem.getMode();
-		if (null != submitMode) {
-			return submitMode;
-		}
-		UIComponent parent = menuItem.getParent();
-		while (null != parent) {
-			if (parent instanceof MenuComponent) {
-				return ((MenuComponent) parent).getMode();
-			}
-			parent = parent.getParent();
-		}
-		
-		return MenuComponent.MODE_SERVER;		
-	}
-	
-	protected String processInlineStyles(FacesContext context, UIMenuItem menuItem, boolean isOnmouseover) {
-		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='");
-		if (null != style) {
-			buffer.append(style.toString() + "; ");
-		}
-		if (isOnmouseover) {
-			buffer.append(selectStyle.toString() + ";';");
-		} else {
-			buffer.append("';");
-		}
-		return buffer.toString();
-	}
-	
+    public void doDecode(FacesContext context, UIComponent component) {
+
+        super.doDecode(context, component);
+
+        ExternalContext exCtx = context.getExternalContext();
+        Map rqMap = exCtx.getRequestParameterMap();
+        Object clnId = rqMap.get(component.getClientId(context));
+        if (clnId == null) {
+            clnId = rqMap.get(component.getClientId(context) + ":hidden");
+        }
+        UIMenuItem menuItem = (UIMenuItem) component;
+        if (clnId != null) {
+
+            // enqueue event here for this component or for component with Id
+            // taken from forId attribute
+
+            String mode = menuItem.getMode();
+            if (!MenuComponent.MODE_NONE.equalsIgnoreCase(mode)) {
+
+                ActionEvent actionEvent = new ActionEvent(menuItem);
+                if (menuItem.isImmediate()) {
+                    actionEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+                } else {
+                    actionEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
+                }
+                menuItem.queueEvent(actionEvent);
+            }
+        }
+    }
+
+    public void initializeResources(FacesContext context, UIMenuItem menuItem)
+            throws IOException {
+        ComponentVariables variables =
+                ComponentsVariableResolver.getVariables(this, menuItem);
+
+        String resource = menuItem.isDisabled()
+                ? ViewUtil.getResourceURL(menuItem.getIconDisabled())
+                : ViewUtil.getResourceURL(menuItem.getIcon());
+        if (resource == null) {
+            resource = getResource("images/spacer.gif").getUri(
+                    context, menuItem);
+        }
+        variables.setVariable("icon", resource);
+
+        if (menuItem.isDisabled()) {
+            variables.setVariable("iconDisabledClasses",
+                    "dr-menu-icon-disabled rich-menu-item-icon-disabled");
+        } else {
+
+            variables.setVariable("onmouseoutInlineStyles",
+                    processInlineStyles(context, menuItem, false));
+            variables.setVariable("onmouseoverInlineStyles",
+                    processInlineStyles(context, menuItem, true));
+
+            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)) {
+                CommandScriptBuilder builder = new CommandScriptBuilder(menuItem);
+                builder.setCheckActionAndListener(true);
+                Object target = menuItem.getAttributes().get("target");
+                if (null != target) {
+                    builder.setTarget((String) target);
+                }
+                builder.setUseOriginalOnclick(true);
+                builder.addCodeBefore("Event.stop(event || window.event);");
+                String id = menuItem.getClientId(context);
+                builder.addParameter(id + ":hidden", id);
+                scriptValue.append(builder.toString());
+            } else {
+                scriptValue.append(
+                        getStringAttributeOrEmptyString(menuItem, "onclick"));
+            }
+            if (resource.length() > 0) {
+                variables.setVariable("onclick", scriptValue.toString());
+            }
+        }
+
+    }
+
+    protected String getStringAttributeOrEmptyString(UIComponent component,
+                                                     String attributeName) {
+        String attributeValue =
+                (String) component.getAttributes().get(attributeName);
+
+        if (null == attributeValue) {
+            attributeValue = "";
+        }
+
+        return attributeValue;
+    }
+
+    protected UIComponent getIconFacet(UIMenuItem menuItem) {
+        UIComponent iconFacet = null;
+        if (menuItem.isDisabled()) {
+            iconFacet = menuItem.getFacet("iconDisabled");
+        } else {
+            iconFacet = menuItem.getFacet("icon");
+        }
+        return iconFacet;
+    }
+
+    protected String resolveSubmitMode(UIMenuItem menuItem) {
+        String submitMode = menuItem.getMode();
+        if (null != submitMode) {
+            return submitMode;
+        }
+        UIComponent parent = menuItem.getParent();
+        while (null != parent) {
+            if (parent instanceof MenuComponent) {
+                return ((MenuComponent) parent).getMode();
+            }
+            parent = parent.getParent();
+        }
+
+        return MenuComponent.MODE_SERVER;
+    }
+
+    protected String processInlineStyles(FacesContext context,
+                                         UIMenuItem menuItem,
+                                         boolean isOnmouseover) {
+        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='");
+        if (null != style) {
+            buffer.append(style.toString() + "; ");
+        }
+        if (isOnmouseover) {
+            buffer.append(selectStyle.toString() + ";';");
+        } else {
+            buffer.append("';");
+        }
+        return buffer.toString();
+    }
 }




More information about the richfaces-svn-commits mailing list