myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Dynamic Menus with JSCookMenu" by SimonKitching
Date Thu, 29 Mar 2007 20:47:22 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by SimonKitching:
http://wiki.apache.org/myfaces/Dynamic_Menus_with_JSCookMenu

------------------------------------------------------------------------------
- Many people ask in the user list how to create a !JsCookMenu dynamically. This is the way:
+ The t:jscookMenu tag can be used to define a menu-bar with pull-down items (and various
other menu layouts).
  
- 1. Create a backing bean (in this example, named 'dynMenu') with the code to generate a
!NavigationMenuItem[], like this:
+ == Defining a static menu ==
+ 
+ If your menu items are fixed, then they can simply be defined using t:navigationMenuItem.
Here's an example. Note that this approach also supports limited "dynamic" menu building by
defining the "rendered" attribute for menu items.
+ 
+ {{{
+    <t:jscookMenu layout="hbr" theme="ThemeOffice">
+       <t:navigationMenuItem itemLabel="File">
+         <t:navigationMenuItem action="new-file" itemLabel="New"/>
+         <t:navigationMenuItem action="open-file" itemLabel="Open"/>
+         <t:navigationMenuItem action="open-file" itemLabel="Close" rendered="#{menuBean.closeFileAvailable}"/>
+       </t:navigationMenuItem>
+       
+       <t:navigationMenuItem itemLabel="Edit">
+         ....
+       </t:navigationMenuItem>
+ }}}
+ 
+ == Defining a dynamic menu ==
+ 
+ When menu items must be added dynamically, or rearranged at runtime, then use the t:navigationMenuItems
tag.
+ 
+ 1. In your jsp use this code to call to a backing bean to generate the menu layout:
  
  {{{
  
+    <t:jscookMenu layout="hbr" theme="ThemeOffice">
+      <%
+        /* Available jscookMenu themes: ThemeIE, ThemeMiniBlack,ThemeOffice, ThemePanel
+           Available jscookMenu layouts: hbr, hbl, hur, hul, vbr,vbl, vur, vul
+           respect to Heng Yuan http://www.cs.ucla.edu/~heng/JSCookMenu
+         */
+      %>
+      <t:navigationMenuItems value="#{dynMenu.navItems}" />
+    </t:jscookMenu>
+ 
+ }}}
+ 
+ 2. Create a backing bean (in this example, named 'dynMenu') with the code to generate a
!NavigationMenuItem[]:
+ 
+ {{{
  import org.apache.myfaces.custom.navmenu.NavigationMenuItem;
  
  public class DynamicMenuTest {
@@ -41, +77 @@

  
  }}}
  
- 2. Then, in your jsp use this code to call to the backing bean and to the generated menu:
- 
- {{{
- 
-    <t:jscookMenu layout="hbr" theme="ThemeOffice">
-                 <%/* Availaible jscookMenu themes: ThemeIE, ThemeMiniBlack,ThemeOffice,
ThemePanel
-              Availaible jscookMenu layout: hbr, hbl, hur, hul, vbr,vbl, vur, vul
-              respect to Heng Yuan http://www.cs.ucla.edu/~heng/JSCookMenu
-         */%>
-                 <t:navigationMenuItems value="#{dynMenu.navItems}" />
-    </t:jscookMenu>
- 
- }}}
- 
  
  NOTE: If you want to have menu items without graphics, use the !NavigationMenuItem constructor
with only 2 parameters:
  
@@ -64, +86 @@

  
  See [http://myfaces.apache.org/tomahawk/apidocs/org/apache/myfaces/custom/navmenu/NavigationMenuItem.html
JavaDoc] for more info.  It would be nice to have a !NavigationMenuItem without a link that
just takes a Label for it's constuctor, so a parent of sub-menu items will not have a link
(as is usually the case).
  
+ == Defining Menu Items ==
+ 
+ ==== Invoking a URL ====
+ When the action attribute of a !NavigationMenuItem object is of form "protocol:/something"
(eg "http://www.apache.org") then this is assumed to be a url; selecting that menu item will
open the specified url in a new window. Note that the URL must be absolute; if there is no
protocol then the value is assumed to be a JSF navigation string (see below).
+ 
+ The !NavigationMenuItem tag has a "target" attribute defined for it. However this attribute
is completely ignored (in tomahawk 1.1.4 and earlier at least); the selected URL is always
opened
+ in an anonymous window.
+ 
+ ==== Invoking Javascript ====
+ When the action attribute is of form "command:text" (eg "javascript:doSomething();") then
selecting that menu item causes the value to be passed to the javascript interpreter for evaluation.
+ 
+ ==== Invoking JSF Navigation ====
+ If the action attribute value does not fall into any other category then it is assumed to
be a JSF "navigation string"; the current page is submitted to the server and the jscookmenu
component causes mavigation to occur to the specified value, ie what page gets rendered depends
upon what the mapping for that "navigation string" is in the JSF navigation definitions for
the webapp.
+ 
+ Q: it appears that support for "value binding" expressions is present. What happens in this
case?
+ 
+ ==== Invoking Action Listeners ====
+ A !NavigationMenuItem can have action-listeners attached to it. When the menu item is selected
and the page is submitted these listeners will be executed.
+ 

Mime
View raw message