You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2011/11/07 19:24:28 UTC

svn commit: r1198857 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/

Author: bommel
Date: Mon Nov  7 18:24:28 2011
New Revision: 1198857

URL: http://svn.apache.org/viewvc?rev=1198857&view=rev
Log:
reenabled accelerator keys on menu

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FacesContextUtils.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FacesContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FacesContextUtils.java?rev=1198857&r1=1198856&r2=1198857&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FacesContextUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/FacesContextUtils.java Mon Nov  7 18:24:28 2011
@@ -42,8 +42,9 @@ public final class FacesContextUtils {
   private static final String TOBAGO_ONEXIT_SCRIPTS = "org.apache.myfaces.tobago.onexitScripts";
   private static final String TOBAGO_ONSUBMIT_SCRIPTS = "org.apache.myfaces.tobago.onsubmitScripts";
   private static final String TOBAGO_POPUPS = "org.apache.myfaces.tobago.popups";
+  private static final String TOBAGO_MENU_ACCELERATORS = "org.apache.myfaces.tobago.menuAccelerators";
+
           
-  
   public static boolean isAjax(FacesContext context) {
     return FacesUtils.getFacesContextAttributes(context).containsKey(TOBAGO_AJAX);
   }
@@ -216,6 +217,28 @@ public final class FacesContextUtils {
     set.add(script);
   }
 
+  public static void clearMenuAcceleratorScripts(FacesContext context) {
+    Set<String> set = (Set<String>) FacesUtils.getFacesContextAttributes(context).get(TOBAGO_MENU_ACCELERATORS);
+    set.clear();
+  }
+
+  public static Set<String> getMenuAcceleratorScripts(FacesContext context) {
+    Set<String> set = (Set<String>) FacesUtils.getFacesContextAttributes(context).get(TOBAGO_MENU_ACCELERATORS);
+    if (set == null) {
+      return Collections.EMPTY_SET;
+    }
+    return set;
+  }
+
+  public static void addMenuAcceleratorScript(FacesContext context, String script) {
+    Set<String> set = (Set<String>) FacesUtils.getFacesContextAttributes(context).get(TOBAGO_MENU_ACCELERATORS);
+    if (set == null) {
+      set = new ListOrderedSet();
+      FacesUtils.getFacesContextAttributes(context).put(TOBAGO_MENU_ACCELERATORS, set);
+    }
+    set.add(script);
+  }
+
   public static Set<AbstractUIPopup> getPopups(FacesContext context) {
     Set<AbstractUIPopup> set = (Set<AbstractUIPopup>) FacesUtils.getFacesContextAttributes(context).get(TOBAGO_POPUPS);
     if (set == null) {

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java?rev=1198857&r1=1198856&r2=1198857&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuRenderer.java Mon Nov  7 18:24:28 2011
@@ -21,6 +21,7 @@ import org.apache.myfaces.tobago.compone
 import org.apache.myfaces.tobago.component.UIMenu;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.internal.util.AccessKeyMap;
+import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
@@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import java.io.IOException;
-import java.util.List;
+import java.util.Set;
 
 public class MenuRenderer extends LayoutComponentRendererBase {
 
@@ -108,19 +109,19 @@ public class MenuRenderer extends Layout
       writer.endElement(HtmlElements.OL);
     }
     writer.endElement(HtmlElements.LI);
+
+    Set<String> accKeyFunctions = FacesContextUtils.getMenuAcceleratorScripts(facesContext);
+    if (!accKeyFunctions.isEmpty()) {
+      HtmlRendererUtils.writeScriptLoader(facesContext, null,
+          accKeyFunctions.toArray(new String[accKeyFunctions.size()]));
+      FacesContextUtils.clearMenuAcceleratorScripts(facesContext);
+    }
+
   }
 
   private void addAcceleratorKey(FacesContext facesContext, UIComponent component, Character accessKey) {
     String clientId = component.getClientId(facesContext);
-    while (component != null && !component.getAttributes().containsKey(MENU_ACCELERATOR_KEYS)) {
-      component = component.getParent();
-    }
-    if (component != null) {
-      List<String> keys = (List<String>) component.getAttributes().get(MENU_ACCELERATOR_KEYS);
-      String jsStatement = HtmlRendererUtils.createOnclickAcceleratorKeyJsStatement(clientId, accessKey, null);
-      keys.add(jsStatement);
-    } else {
-      LOG.warn("Can't find menu root component!");
-    }
+    String jsStatement = HtmlRendererUtils.createOnclickAcceleratorKeyJsStatement(clientId, accessKey, null);
+    FacesContextUtils.addMenuAcceleratorScript(facesContext, jsStatement);
   }
 }