You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jl...@apache.org on 2006/04/07 11:40:22 UTC

svn commit: r392232 - in /myfaces/tomahawk/trunk/sandbox/core/src/main: java/org/apache/myfaces/custom/fisheye/ resources-facesconfig/META-INF/ tld/

Author: jlust
Date: Fri Apr  7 02:40:21 2006
New Revision: 392232

URL: http://svn.apache.org/viewcvs?rev=392232&view=rev
Log:
Renamed the FishEyeList component to FishEyeNavigationMenu, and added the ability to render
UINavigationMenuItem children.
There is still a problem with the decode method of the renderer though: the actions and actionListeners
are not being invoked.
I also added the example from the Dojo Toolkit.

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenu.java
      - copied, changed from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeList.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuRenderer.java
      - copied, changed from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuTag.java
      - copied, changed from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListTag.java
Removed:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeList.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListTag.java
Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld

Copied: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenu.java (from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeList.java)
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenu.java?p2=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenu.java&p1=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeList.java&r1=392209&r2=392232&rev=392232&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeList.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenu.java Fri Apr  7 02:40:21 2006
@@ -28,7 +28,7 @@
  * @author Jurgen Lust (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class HtmlFishEyeList extends Div
+public class HtmlFishEyeNavigationMenu extends Div
 {
     public static final String COMPONENT_TYPE = "org.apache.myfaces.FishEyeList";
     private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.FishEyeList";
@@ -51,7 +51,7 @@
     private String _labelEdge;
     private String _orientation;
 
-    public HtmlFishEyeList()
+    public HtmlFishEyeNavigationMenu()
     {
         setRendererType(DEFAULT_RENDERER_TYPE);
     }
@@ -149,7 +149,7 @@
 
     public boolean getRendersChildren()
     {
-        return false;
+        return true;
     }
 
     /**

Copied: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuRenderer.java (from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListRenderer.java)
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuRenderer.java?p2=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuRenderer.java&p1=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListRenderer.java&r1=392209&r2=392232&rev=392232&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuRenderer.java Fri Apr  7 02:40:21 2006
@@ -16,15 +16,22 @@
 package org.apache.myfaces.custom.fisheye;
 
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
 
 import org.apache.myfaces.custom.dojo.DojoUtils;
+import org.apache.myfaces.custom.navmenu.UINavigationMenuItem;
+import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
+import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
 
 /**
  * Renderer for the FishEyeList component
@@ -32,12 +39,15 @@
  * @author Jurgen Lust (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class HtmlFishEyeListRenderer extends Renderer
+public class HtmlFishEyeNavigationMenuRenderer extends HtmlLinkRenderer
 {
     public static final String ATTACH_EDGE_ATTR = "dojo:attachEdge";
 
+    public static final String CAPTION_ATTR = "caption";
+    public static final String DOJO_ITEM_STYLE_CLASS = "dojo-FisheyeListItem";
     public static final String DOJO_STYLE_CLASS = "dojo-FisheyeList";
     public static final String EFFECT_UNITS_ATTR = "dojo:effectUnits";
+    public static final String ICON_SRC_ATTR = "dojo:iconsrc";
     public static final String ITEM_HEIGHT_ATTR = "dojo:itemHeight";
     public static final String ITEM_MAX_HEIGHT_ATTR = "dojo:itemMaxHeight";
     public static final String ITEM_MAX_WIDTH_ATTR = "dojo:itemMaxWidth";
@@ -47,13 +57,16 @@
     public static final String ORIENTATION_ATTR = "dojo:orientation";
     public static final String RENDERER_TYPE = "org.apache.myfaces.FishEyeList";
 
+    /**
+     * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
     public void encodeBegin(FacesContext context, UIComponent component)
             throws IOException
     {
         System.out.println("rendering fisheye");
         if (component.isRendered())
         {
-            HtmlFishEyeList fisheye = (HtmlFishEyeList) component;
+            HtmlFishEyeNavigationMenu fisheye = (HtmlFishEyeNavigationMenu) component;
             ResponseWriter writer = context.getResponseWriter();
             //initialize DOJO
             String javascriptLocation = (String) component.getAttributes().get(
@@ -85,6 +98,29 @@
         }
     }
 
+    /**
+     * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
+    public void encodeChildren(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        ResponseWriter writer = context.getResponseWriter();
+        List children = component.getChildren();
+        for (Iterator cit = children.iterator(); cit.hasNext();)
+        {
+            UIComponent child = (UIComponent) cit.next();
+            if (!child.isRendered())
+                continue;
+            if (child instanceof UINavigationMenuItem)
+            {
+                renderMenuItem(context, writer, (UINavigationMenuItem) child);
+            }
+        }
+    }
+
+    /**
+     * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
     public void encodeEnd(FacesContext context, UIComponent component)
             throws IOException
     {
@@ -95,8 +131,83 @@
         }
     }
 
+    /**
+     * @see javax.faces.render.Renderer#getRendersChildren()
+     */
+    public boolean getRendersChildren()
+    {
+        //always render the menu items
+        return true;
+    }
+
+    protected void renderMenuItem(FacesContext context, ResponseWriter writer,
+            UINavigationMenuItem item) throws IOException
+    {
+        //find the enclosing form
+        FormInfo formInfo = findNestingForm(item, context);
+        String clientId = item.getClientId(context);
+        if (formInfo == null)
+        {
+            throw new IllegalArgumentException("Component " + clientId
+                    + " must be embedded in an form");
+        }
+        UIForm nestingForm = formInfo.getForm();
+        String formName = formInfo.getFormName();
+
+        StringBuffer onClick = new StringBuffer();
+
+        //call the clear_<formName> method
+        onClick.append(
+                HtmlRendererUtils
+                        .getClearHiddenCommandFormParamsFunctionName(formName))
+                .append("();");
+        String jsForm = "document.forms['" + formName + "']";
+
+        if (MyfacesConfig.getCurrentInstance(context.getExternalContext())
+                .isAutoScroll())
+        {
+            org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils
+                    .appendAutoScrollAssignment(onClick, formName);
+        }
+
+        //add id parameter for decode
+        String hiddenFieldName = HtmlRendererUtils
+                .getHiddenCommandLinkFieldName(formName);
+        onClick.append(jsForm);
+        onClick.append(".elements['").append(hiddenFieldName).append("']");
+        onClick.append(".value='").append(clientId).append("';");
+        addHiddenCommandParameter(context, nestingForm, hiddenFieldName);
+
+        //add the target window
+        String target = item.getTarget();
+        if (target != null && target.trim().length() > 0)
+        {
+            onClick.append(jsForm);
+            onClick.append(".target='");
+            onClick.append(target);
+            onClick.append("';");
+        }
+
+        // onSubmit
+        onClick.append("if(").append(jsForm).append(".onsubmit){var result=")
+                .append(jsForm).append(
+                        ".onsubmit();  if( (typeof result == 'undefined') || result ) {"
+                                + jsForm + ".submit();}}else{");
+
+        //submit
+        onClick.append(jsForm);
+        onClick.append(".submit();}return false;"); //return false, so that browser does not handle the click
+
+        writer.startElement(HTML.DIV_ELEM, item);
+        writer.writeAttribute(HTML.CLASS_ATTR, DOJO_ITEM_STYLE_CLASS, null);
+        writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
+        writer.writeAttribute(CAPTION_ATTR, item.getItemLabel(), null);
+        writer.writeAttribute(ICON_SRC_ATTR, item.getIcon(), null);
+        writer.endElement(HTML.DIV_ELEM);
+    }
+
     protected void writeAttribute(ResponseWriter writer,
-            HtmlFishEyeList fisheye, String name, Object value)
+            HtmlFishEyeNavigationMenu fisheye, String name, Object value)
             throws IOException
     {
         if (name != null && value != null)

Copied: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuTag.java (from r392209, myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListTag.java)
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuTag.java?p2=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuTag.java&p1=myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListTag.java&r1=392209&r2=392232&rev=392232&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeListTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/fisheye/HtmlFishEyeNavigationMenuTag.java Fri Apr  7 02:40:21 2006
@@ -27,7 +27,7 @@
  * @author Jurgen Lust (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class HtmlFishEyeListTag extends DivTag
+public class HtmlFishEyeNavigationMenuTag extends DivTag
 {
     private String _attachEdge;
     private String _effectUnits;
@@ -46,7 +46,7 @@
 
     public String getComponentType()
     {
-        return HtmlFishEyeList.COMPONENT_TYPE;
+        return HtmlFishEyeNavigationMenu.COMPONENT_TYPE;
     }
 
     public String getEffectUnits()
@@ -91,7 +91,7 @@
 
     public String getRendererType()
     {
-        return HtmlFishEyeListRenderer.RENDERER_TYPE;
+        return HtmlFishEyeNavigationMenuRenderer.RENDERER_TYPE;
     }
 
     public void release()
@@ -156,7 +156,7 @@
     protected void setProperties(UIComponent component)
     {
         super.setProperties(component);
-        HtmlFishEyeList fisheye = (HtmlFishEyeList) component;
+        HtmlFishEyeNavigationMenu fisheye = (HtmlFishEyeNavigationMenu) component;
         FacesContext context = FacesContext.getCurrentInstance();
         Application app = context.getApplication();
         if (_attachEdge != null)

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=392232&r1=392231&r2=392232&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Fri Apr  7 02:40:21 2006
@@ -156,7 +156,7 @@
   
   <component>
   	<component-type>org.apache.myfaces.FishEyeList</component-type>
-  	<component-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeList</component-class>
+  	<component-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeNavigationMenu</component-class>
   </component>
 
   
@@ -349,7 +349,7 @@
     <renderer>
 		<component-family>javax.faces.Output</component-family>
 		<renderer-type>org.apache.myfaces.FishEyeList</renderer-type>
-		<renderer-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeListRenderer</renderer-class>
+		<renderer-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeNavigationMenuRenderer</renderer-class>
 	</renderer>
 
    <!-- <renderer>

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=392232&r1=392231&r2=392232&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Fri Apr  7 02:40:21 2006
@@ -1021,12 +1021,12 @@
     
 	<!--  fishEyeList -->
 	<tag>
-		<name>fishEyeList</name>
-		<tag-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeListTag</tag-class>
+		<name>fishEyeNavigationMenu</name>
+		<tag-class>org.apache.myfaces.custom.fisheye.HtmlFishEyeNavigationMenuTag</tag-class>
 		<body-content>JSP</body-content>
 		<display-name>fishEye List component</display-name>
 		<description>Provide a FishEye toolbar component from the DOJO toolkit</description>
-		&faces_id_required_attribute;
+		&faces_id_optional_attribute;
 		&faces_rendered_attribute;
 
 		&html_fisheye_list_attributes;