JIRA appears to be down at the moment, but as I can't compile the code I missed 
a bug in my patch.  The attached patch handles the recursion a bit better (only 
finding the enclosing form once instead of once per recurssion) and fixes the 
bug.

 


----------------------------------------------
Neal Haggard
Senior Systems Developer
Knowledge Management Center
SAS Institute

-----Original Message-----
From: Neal Haggard (JIRA) [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 13, 2005 5:24 PM
To: [email protected]
Subject: [jira] Updated: (MYFACES-27) JSCookmenu cannot be used for storing data

     [ http://issues.apache.org/jira/browse/MYFACES-27?page=all ]

Neal Haggard updated MYFACES-27:
--------------------------------

    Attachment: jscookFormPatch.txt

I've attached a patch which will walk up the parent of the JSCookMenu 
Navigation Item and look for the first UIForm component it finds.  If found, it 
uses the client id for that instead of 'linkDummyForm' when outputting the 
JavaScript for item.

Please contact me if you have any questions about this.  

> JSCookmenu cannot be used for storing data
> ------------------------------------------
>
>          Key: MYFACES-27
>          URL: http://issues.apache.org/jira/browse/MYFACES-27
>      Project: MyFaces
>         Type: Bug
>     Versions: 1.0.7 beta
>  Environment: JBoss 4.0
>     Reporter: Tobias Neubert
>     Assignee: Thomas Spiegl
>     Priority: Critical
>  Attachments: jscookFormPatch.txt
>
> JSCookmenu has hardcoded "immediate" attribute on "true". This cause that an 
> action, which should store data from the view, is executed after the 
> apply_request_values-phase instead of the application-execute-phase. But at 
> that time the model values are not updated with the view-values, so a empty 
> objekt is stored.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Index: C:/Documents and 
Settings/nehagg/workspace/MyFaces-Tomahawk/src/java/org/apache/myfaces/custom/navmenu/jscookmenu/HtmlJSCookMenuRenderer.java
===================================================================
--- C:/Documents and 
Settings/nehagg/workspace/MyFaces-Tomahawk/src/java/org/apache/myfaces/custom/navmenu/jscookmenu/HtmlJSCookMenuRenderer.java
       (revision 320898)
+++ C:/Documents and 
Settings/nehagg/workspace/MyFaces-Tomahawk/src/java/org/apache/myfaces/custom/navmenu/jscookmenu/HtmlJSCookMenuRenderer.java
       (working copy)
@@ -15,31 +15,19 @@
  */
 package org.apache.myfaces.custom.navmenu.jscookmenu;
 
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.text.html.HTML;
+
 import org.apache.myfaces.component.html.util.AddResource;
 import org.apache.myfaces.custom.navmenu.NavigationMenuItem;
 import org.apache.myfaces.custom.navmenu.NavigationMenuUtils;
 import org.apache.myfaces.custom.navmenu.UINavigationMenuItem;
-import org.apache.myfaces.el.SimpleActionMethodBinding;
-import org.apache.myfaces.renderkit.RendererUtils;
-import org.apache.myfaces.renderkit.JSFAttr;
-import org.apache.myfaces.renderkit.html.HtmlRenderer;
-import org.apache.myfaces.renderkit.html.HTML;
-import org.apache.myfaces.renderkit.html.util.DummyFormResponseWriter;
-import org.apache.myfaces.renderkit.html.util.DummyFormUtils;
-import org.apache.myfaces.renderkit.html.util.JavascriptUtils;
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.ActionEvent;
-import javax.faces.webapp.UIComponentTag;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author Thomas Spiegl
  * @version $Revision$ $Date$
@@ -138,19 +126,51 @@
             encodeNavigationMenuItems(context, script,
                                       (NavigationMenuItem[]) list.toArray(new 
NavigationMenuItem[list.size()]),
                                       uiNavMenuItemList,
-                                      myId);
+                                      myId, getFormName(component,context));
 
             script.append("];");
             writer.writeText(script.toString(),null);
             writer.endElement(HTML.SCRIPT_ELEM);
         }
     }
+    
+    /**
+     * Method getFormName.
+     * 
+     * @param sortColumnHeader SortColumnHeader
+     * @param facesContext FacesContext
+     * @return String
+     */
+    private String getFormName(UIComponent component,
+            FacesContext facesContext) {
+        // See if we are in a form
+        UIForm parentForm = getParentForm(component);
+        if (parentForm != null) { return parentForm.getClientId(facesContext); 
}
 
+        // Not in a form. Return the child form's name
+        return "linkDummyForm";
+    }
+    
+    /**
+     * Get the parent UIForm. If no parent is a UIForm then returns null.
+     * 
+     * @param component
+     * @return UIForm
+     */
+    private UIForm getParentForm(UIComponent component) {
+        // See if we are in a form
+        UIComponent parent = component.getParent();
+        while (parent != null && !(parent instanceof UIForm)) {
+            parent = parent.getParent();
+        }
+        return (UIForm) parent;
+    }
+
     private void encodeNavigationMenuItems(FacesContext context,
                                            StringBuffer writer,
                                            NavigationMenuItem[] items,
                                            List uiNavMenuItemList,
-                                           String menuId)
+                                           String menuId, String formName)
         throws IOException
     {
         for (int i = 0; i < items.length; i++)
@@ -213,7 +233,10 @@
             {
                 writer.append("null");
             }
-            writer.append(", 'linkDummyForm', null"); // TODO Change here to 
allow the use of non dummy form if possible.
+            writer.append(", '");
+            // Change here to allow the use of non dummy form.
+            writer.append(formName );
+            writer.append("', null"); 
 
             if (item.isRendered() && ! item.isDisabled()) {
                 // render children only if parent is visible/enabled
@@ -224,10 +247,10 @@
                     if (uiNavMenuItem != null)
                     {
                         encodeNavigationMenuItems(context, writer, menuItems,
-                                uiNavMenuItem.getChildren(), menuId);
+                                uiNavMenuItem.getChildren(), menuId, formName);
                     } else {
                         encodeNavigationMenuItems(context, writer, menuItems,
-                                new ArrayList(1), menuId);
+                                new ArrayList(1), menuId, formName);
                     }
                 }
             }

Reply via email to