Oracle® Fusion Middleware Web User Interface Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) Part Number B31973-03 |
|
|
View PDF |
This chapter describes how to create menu bars and toolbars that contain tool buttons.
This chapter includes the following sections:
Menus and toolbars allow users to choose from a specified list of options (in the case of a menu) or to click buttons (in the case of a toolbar) to cause some change to the application. For example, the File Explorer application contains both a menu bar and a toolbar, as shown in Figure 14-1.
When a user chooses a menu item in the menu bar, the menu
component displays a list of menu items, as shown in Figure 14-2.
Note that as shown in Figure 14-3, menus can be nested.
Toolbars also allow a user to invoke some sort of action on an application. The toolbar buttons invoke an action, or you can use a button opens a popup menu that behaves the same as a standard menu.
You can organize toolbars and menu bars using a toolbox. The toolbox gives you the ability to define relative sizes for the toolbars on the same line and to define several layers of toolbars and menu bars vertically.
Note:
If you want to create menus and toolbars in a table, then follow the procedures as documented in Section 10.8, "Displaying Table Menus, Toolbars, and Status Bars".Use the menuBar
component to render a bar that contains the menu bar items (such as File in the File Explorer application). Each item on a menu bar is rendered by a menu
component, which holds a vertical menu. Each vertical menu consists of a list of commandMenuItem
components that can invoke some operation on the application. You can nest menu components inside menu components to create submenus. The different components used to create a menu are shown in Figure 14-4.
Menus and submenus can be made to be detachable and to float on the browser window. Figure 14-5 shows how the New submenu in the File menu can be configured to be detachable. The top of the menu is rendered with a bar to denote that it can be detached.
The user can drag the detachable menu to anywhere within the browser. When the mouse button is released, the menu stays on top of the application until the user closes it, as shown in Figure 14-6
Tip:
Consider using detachable menus when you expect users to:Execute similar commands repeatedly on a page.
Execute similar commands on different rows of data in a large table, tree table, or tree.
View data in long and wide tables or tree tables, and trees. Users can choose which columns or branches to hide or display with a single click.
Format data in long or wide tables, tree tables, or trees.
The menu
and commandMenuItem
components can each include an icon image. Figure 14-7 shows the Delete menu item configured to display a delete icon.
You can configure commandMenuItem
components to be specific types that change how they are displayed when the menu item is chosen. For example, you can configure a commandMenuItem
component to display a checkmark or a radio button next to the label when the item is chosen. Figure 14-8 shows the View menu with the Folders and Search menu items configured to use a checkmark when chosen. The Table, Tree Table, and List menu items are configured to be radio buttons, and allow the user to choose only one of the group.
You can also configure a commandMenuItem
component to have an antonym. Antonyms display different text when the user chooses a menu item. For example, Figure 14-9 shows an Undo menu item in the Edit menu (added to the File Explorer application for this example).
By configuring the commandMenuItem
component for the Undo menu item to be an antonym, you can make it so that once a user chooses Undo, the next time the user returns to the menu, the menu item will display the antonym Restore, as shown in Figure 14-10.
Because an action is expected when a user chooses a menu item, you must bind the action
or actionListener
attribute of the commandMenuItem
component to some method that will execute the needed functionality.
You can use more than one menu bar by enclosing them in a toolbox component. You can also use the toolbox component to group any number of menu bars and toolbars. For more information, see Section 14.3, "Using Toolbars".
Along with commandMenuItem
components, a menu can also include one or more goMenuItem
components. These are navigation components similar to the goLink
component, in that they perform direct page navigation, without delivering an ActionEvent
event. Figure 14-11 shows three goMenuItem
components used to navigate to external web sites.
Aside from menus that are invoked from menu bars, you can also create context menus that are invoked when a user right-clicks a UI component, and popup menus that are invoked when a user clicks a command component. For more information, see Section 13.3, "Using Command Components to Show Popup Elements". Note that menus and menu bars do not render on printable pages.
Note:
ADF Faces provides a button with built-in functionality that allows a user to view a printable version of the current page. Menus and menu bars do not render on these pages. For more information, see Section 5.6, "Using Client Behavior Tags".By default, the contents of the menu are delivered immediately, as the page is rendered. If you plan on having a large number of children in a menu (multiple menu
and commandMenuItem
components), you can choose to configure the menu to use lazy content delivery. This means that the child components are not retrieved from the server until the menu is accessed.
Note:
Content delivery for menus used as pop-up context menus is determined by the parent popup dialog, and not the menu itself.You can also create menus that mainly provide navigation throughout the application, and are not used to cause any change on a selected item in an application. To create this type of menu, see Section 18.6, "Using a Menu Model to Create a Page Hierarchy".
To create a menu, you first have to create a menu bar to hold the menus. You then add and configure menu
and commandMenuItem
components as needed.
Note:
If you want to create menus in a table, then follow the procedures as outlined in Section 10.8, "Displaying Table Menus, Toolbars, and Status Bars".To create and use menus in a menu bar:
Create a menuBar
component by dragging and dropping a Panel Menu Bar from the Component Palette to the JSF page.
Insert the desired number of menu
components into the menu bar by dragging a Menu from the Component Palette and dropping it as a child to the menuBar
component.
You can also insert commandMenuItem
components directly into a menu bar by dragging and dropping a Menu Item from the Component Palette. Doing so creates a commandMenuItem
component that renders similar to a toolbar button.
Tip:
Menu bars also allow you to use theiterator
, switcher
, and group
components as direct children, providing these components wrap child components that would usually be direct children of the menu bar.For each menu
component, expand the Appearance section in the Property Inspector and set the following attributes:
text
: Enter text for the menu's label. If you wish to also provide an access key (a letter a user can use to access the menu using the keyboard), then leave this attribute blank and enter a value for textAndAccessKey
instead.
textAndAccessKey
: Enter the menu label and access key, using conventional ampersand notation. For example, &File
sets the menu label to File, and at the same time sets the menu access key to the letter F
. For more information about access keys and the ampersand notation, see Section 22.3, "Defining Access Keys for ADF Faces Components".
icon
: Enter the URI of the image file you want to display before the menu item label.
If you want the menu to be detachable, expand the Behavior section in the Property Inspector. Set the detachable
attribute to true
if you want to make this menu a detachable menu (as shown in Figure 14-5). At runtime, the user can drag the menu to detach it, and drop it anywhere on the screen (as shown in Figure 14-6).
If you want the menu to use lazy content delivery, expand the Other section in the Property Inspector and set the ContentDelivery
attribute to lazy
.
Note:
If you use lazy content delivery, any accelerators set on the childcommandMenuItem
components will not work because the contents of the menu are not known until the menu is accessed. If your menu must support accelerators, then the contentDelivery
attribute must be set to immediate
.Note:
If the menu will be used inside a popup dialog or window, leave the content delivery set toimmediate
, because the popup dialog or window will determine the content delivery for the menu.Within each menu
component, to create menu items that invoke some sort of action along with navigation, drag and drop MenuItems from the Component Palette to insert a series of commandMenuItem
components to define the items in the vertical menu.
If needed, you can wrap the commandMenuItem
components within a group component to display the items as a group. Example 14-1 shows simplified code for grouping the Folders and Search menu items in one group, the Table, Tree Table and List menu items in a second group, and the Refresh menu item by itself at the end.
Example 14-1 Grouping Menu Items
<af:menu id="viewMenu" <af:group> <af:commandMenuItem type="check" text="Folders"/> <af:commandMenuItem type="check" text="Search"/> </af:group> <af:group> <af:commandMenuItem type="radio" text="Table"/> <af:commandMenuItem type="radio" text="Tree Table"/> <af:commandMenuItem type="radio" text="List"/> </af:group> <af:commandMenuItem text="Refresh"/> </menu>
Figure 14-12 shows how the menu is displayed.
Tip:
By default, only up to 14 items are displayed in the menu. If more than 14 items are added to a menu, the first 14 are displayed along with a scrollbar, which can be used to access the remaining items. If you wish to change the number of visible items, edit theaf|menu {-tr-visible-items
} skinning key. For more information, see Chapter 20, "Customizing the Appearance Using Styles and Skins".You can also insert another menu
component into an existing menu
component to create a submenu (as shown in Figure 14-3).
Tip:
Menus also allow you to use the iterator and switcher components as direct children, providing these components wrap child components that would usually be direct children of the menu.For each commandMenuItem
component, expand the Common section in the Property Inspector and set the following attributes:
type
: Specify a type for this menu item. When a menu item type is specified, ADF Faces adds a visual indicator (such as a checkmark) and a toggle behavior to the menu item. At runtime, when the user selects a menu item with a specified type (other than default), ADF Faces toggles the visual indicator or menu item label. Use one of the following acceptable type
values:
check
: Toggles a checkmark next to the menu item label. The checkmark is displayed when the menu item is chosen.
radio
: Toggles a radio button next to the menu item label. The radio button is displayed when the menu item is chosen.
antonym
: Toggles the menu item label. The value set in the selectedText
attribute is displayed when the menu item is chosen, instead of the menu item defined by the value of text
or textAndAccessKey
(which is what is displayed when the menu item is not chosen). If you select this type, you must set a value for the selectedText
attribute.
default
: Assigns no type to this menu item. The menu item is displayed in the same manner whether or not it is chosen.
text
: Enter text for the menu item's label. If you wish to also provide an access key (a letter a user can use to access the item using the keyboard), then leave this attribute blank and enter a value for the textAndAccessKey
attribute instead. Or, you can set the access key separately using the accessKey
attribute.
selected
: Set to true
to have this menu item appear to be chosen. The selected
attribute is supported for check-, radio-, and antonym-type menu items only.
selectedText
: Set the alternate label to display for this menu item when the menu item is chosen. This value is ignored for all types except antonym.
Example 14-2 shows the Special menu with one group of menu items configured to use radio buttons and another group of menu items configured to show checkmarks when chosen. The last group contains a menu item configured to be the antonym Open when it is first displayed, and then it toggles to Closed.
Example 14-2 Using the Type Attribute in a commandMenuItem Component
<af:menu text="Special"> <af:group> <af:commandMenuItem text="Radio 1" type="radio" selected="true" <af:commandMenuItem text="Radio 2" type="radio"/> <af:commandMenuItem text="Radio 3" type="radio"> </af:group> <af:group> <af:commandMenuItem text="Check 1" type="check" selected="true" <af:commandMenuItem text="Check 2" type="check"/> </af:group> <af:commandMenuItem text="Open (antonym)" type="antonym" selectedText="Close (antonym)"/> </af:menu>
Figure 14-13 shows how the menu will be displayed when it is first accessed.
Expand the Appearance section and set the following attributes:
icon
: Enter the URI of the image file you want to display before the menu item label.
accelerator
: Enter the keystroke that will activate this menu item's command when the item is chosen, for example, Control O
. ADF Faces converts the keystroke and displays a text version of the keystroke (for example, Ctrl+O) next to the menu item label, as shown in Figure 14-3.
Note:
If you choose to use lazy content delivery, any accelerators set on the childcommandMenuItem
components will not work because the contents of the menu are not known until it is accessed. If your menu must support accelerator keys, then the contentDelivery
attribute must be set to immediate
.textAndAccessKey
: Enter the menu item label and access key, using conventional ampersand notation. For example, &Save
sets the menu item label to Save
, and at the same time sets the menu item access key to the letter S
. For more information about access keys and the ampersand notation, see Section 22.3, "Defining Access Keys for ADF Faces Components".
Expand the Behavior section and set the following attributes:
action
: Use an EL expression that evaluates to an action method in an object (such as a managed bean) that will be invoked when this menu item is chosen. The expression must evaluate to a public method that takes no parameters, and returns a java.lang.Object
object.
If you want to cause navigation in response to the action generated by commandMenuItem
component, instead of entering an EL expression, enter a static action outcome value as the value for the action
attribute. You then must either set the partialSubmit
attribute to false
, or use a redirect. For more information about configuring navigation in your application, see Section 2.3, "Defining Page Flows".
actionListener
: Specify the expression that refers to an action listener method that will be notified when this menu item is chosen. This method can be used instead of a method bound to the action
attribute, allowing the action
attribute to handle navigation only. The expression must evaluate to a public method that takes an ActionEvent
parameter, with a return type of void
.
To create a menu item that simply navigates (usually to an external site), drag and drop a Go Menu Item from the Component Palette as a child to the menu.
In the Property Inspector, expand the Other section and set the following attributes:
destination
: Enter the URI of the page to which the link should navigate. For example, to navigate to the Oracle Corporation Home Page, you would enter http://www.oracle.com.
icon
: Enter the URI of an image file.
targetFrame
: Set the targetFrame
attribute to specify where the new page should display. Acceptable values are
_blank
: The link opens the document in a new window.
_parent
: The link opens the document in the window of the parent. For example, if the link appeared in a dialog, the resulting page would render in the parent window.
_self
: The link opens the document in the same page or region.
_top
: The link opens the document in a full window, replacing the entire page.
text
: Enter the text for the link.
Tip:
Instead, you can use thetextAndAccessKey
attribute to provide a single value that defines the label and the access key to use for the link. For information about how to define access keys, see Section 22.3.1, "How to Define Access Keys for an ADF Faces Component"Along with menus, you can create toolbars in your application that contain toolbar buttons used to initiate some operation in the application. The buttons can display text, an icon, or a combination of both. Toolbar buttons can also open menus in a popup window. Along with toolbar buttons, other UI components, such as dropdown lists, can be displayed in toolbars. Figure 14-14 shows the toolbar from the File Explorer application.
Tip:
Toolbars can also include command buttons and command links (including thecommandImageLink
component) instead of toolbar buttons. However, toolbar buttons provide additional functionality, such as opening popup menus. Toolbar buttons can also be used outside of a toolbar
componentThe toolbar component can contain many different types of components, such as inputText
components, LOV components, selection list components, and command components. ADF Faces also includes a commandToolbarButton
component that has a popup
facet allowing you to provide popup menus from a toolbar button. You can configure your toolbar button so that it only opens the popup dialog and does not fire an action event. As with menus, you can group related toolbar buttons on the toolbar using the group
component.
You can use more than one toolbar by enclosing them in a toolbox. Doing so stacks the toolbars so that the first toolbar on the page is displayed on the top, and the last toolbar is displayed on the bottom. For example, in the File Explorer application, the currently selected folder name is displayed in the Current Location toolbar, as shown in Figure 14-14. When you use more than one toolbar, you can set the flex
attribute on the toolbars to determine which toolbar should take up the most space. In this case, the Current Location toolbar is set to be the longest.
If you wish toolbars to be displayed next to each other (rather than stacked), you can enclose them in a group
component.
Tip:
You can also use thetoolbox
component to group menu bars with toolbars, or to group multiple menu bars. As with grouping toolbars, use the group
component to group menu bars and toolbars on the same row.Within a toolbar, you can set one component to stretch so that the toolbar will always be the same size as its parent container. For example, in the File Explorer application, the lower toolbar that displays the current location contains the component that shows the selected folder. This component is set to stretch so that when the window is resized, that component and the toolbar will always be the same width as the parent. However, because no component in the top toolbar is set to stretch, it does not change size when the window is resized. When a window is resized such that all the components within the toolbar can no longer be displayed, the toolbar displays an overflow icon, as identified by the arrow cursor in the upper right-hand corner of Figure 14-15.
Clicking that overflow icon displays the remaining components in a popup window, as shown in Figure 14-16.
When you expect overflow to occur in your toolbar, it is best to wrap it in a toolbox that has special layout logic to help in the overflow.
Note:
Menu bars grouped in a toolbox do not support overflow. Therefore, ensure that the toolbox is configured so that there is room to display all menu items.If you are going to use more than one toolbar
component on a page, or menu bars with toolbars, you first create the toolbox
component to hold them. You then create the toolbars, and last, you create the toolbar buttons.
Tip:
If you encounter layout issues with single toolbars or menu bars, consider wrapping them in a toolbox component, because this component can handle overflow and layout issues.To create and use toolbars:
If you plan on using more than one toolbar or a combination of toolbars and menu bars, create a toolbox
component by dragging and dropping a Toolbox component from the Layout section of the Component Palette.
Tip:
ThepanelHeader
, showDetailHeader
, and showDetailItem
components support a toolbar
facet for adding toolboxes and toolbars to section headers and accordion panel headers.Create a toolbar
component by dragging a Toolbar from the Common Components section of the Component Palette and dropping it onto the JSF page. If you are using a toolbox
component, the toolbar
should be a direct child of the toolbox
component.
Tip:
Toolboxes also allow you to use the iterator, switcher, and group components as direct children, providing these components wrap child components that would usually be direct children of the toolbox.If grouping more than one toolbar within a toolbox, expand the Appearance section and set the flex
attributes on the toolbars to determine the relative sizes of each of the toolbars. The higher the number given for the flex
attribute, the longer the toolbox will be. Example 14-3 shows that toolbar2
will be the longest, toolbar4
will be the next longest, and because their flex
attributes are not set, the remaining toolbars will be the same size and shorter than toolbar4
.
Example 14-3 Flex Attribute Determines Length of Toolbars
<af:toolbox> <af:toolbar id="toolbar1" flex="0"> <af:commandToolbarButton text="ButtonA"/> </af:toolbar> <af:toolbar id="toolbar2" flex="2"> <af:commandToolbarButton text="ButtonB"/> </af:toolbar> <af:toolbar id="toolbar3" flex="0"> <af:commandToolbarButton text="ButtonC"/> </af:toolbar> <af:toolbar id="toolbar4" flex="1"> <af:commandToolbarButton text="ButtonD"/> </af:toolbar> </af:toolbox>
Performance Tip:
At runtime, when available browser space is less than the space needed to display the contents of the toolbox, ADF Faces automatically displays overflow icons that enable users to select and navigate to those items that are out of view. The number of child components within atoolbox
component, and the complexity of the children, will affect the performance of the overflow. You should set the size of the toolbox
component to avoid overflow when possible. For more information, see Section 14.3.2, "What Happens at Runtime: Determining the Size of Toolbars".Tip:
You can use thegroup
component to group toolbars (or menu bars and toolbars) that you want to appear on the same row. If you do not use the group
component, the toolbars will appear on subsequent rows.For information about how the flex
attribute works, see Section 14.3.2, "What Happens at Runtime: Determining the Size of Toolbars".
Insert components into the toolbar as needed. To create a commandToolbarButton
drag a ToolbarButton from the Component Palette and drop it as a direct child of the toolbar
component.
Tip:
You can use thegroup
component to wrap related buttons on the bar. Doing so inserts a separator between the groups, as shown surrounding the group for the Select Skin dropdown list and Refresh button shown in Figure 14-14.
Toolbars also allow you to use the iterator and switcher components as direct children, providing these components wrap child components that would usually be direct children of the toolbar.
Tip:
You can place other components, such as command buttons and links, input components, and select components in a toolbar. However, they may not have the capability to stretch. For details about stretching the toolbar, see Step 9.Tip:
If you plan to support changing thevisible
attribute of the button through active data (for example, data being pushed from the data source will determine whether nor not the toolbar is displayed), then you should use the activeCommandToolbarButton
component instead of the commandToolbarButton component. Create an activeCommandToolbarButton
component by dragging a ToolbarButton (Active) from the Component Palette.For each commandToolbarButton
component, expand the Common section of the Property Inspector and set the following attributes:
type
: Specify a type for this toolbar button. When a toolbar button type is specified, an icon can be displayed when the button is clicked. Use one of the following acceptable type
values:
check
: Toggles to the depressedIcon
value if selected or to the default icon
value if not selected.
radio
: When used with other toolbar buttons in a group, makes the button currently clicked selected, and toggles the previously clicked button in the group to unselected.
Note:
When setting the type toradio
, you must wrap the toolbar button in a group
tag that includes other toolbar buttons whose types are set to radio
as well.default
: Assigns no type to this toolbar button.
selected
: Set to true
to have this toolbar button appear as though it is selected. The selected
attribute is supported for checkmark- and radio-type toolbar buttons only.
icon
: Enter the URI of the image file you want to display before this toolbar button label.
text
: Enter the label for this toolbar button.
action
: Use an EL expression that evaluates to an action method in an object (such as a managed bean) that will be invoked when a user presses this button. The expression must evaluate to a public method that takes no parameters, and returns a java.lang.Object
object.
If you want to cause navigation in response to the action generated by the button, instead of entering an EL expression, enter a static action outcome value as the value for the action
attribute. You then must either set partialSubmit
to false
, or use a redirect. For more information about configuring navigation, see Section 2.3, "Defining Page Flows".
actionListener
: Specify the expression that refers to an action listener method that will be notified when a user presses this button. This method can be used instead of a method bound to the action
attribute, allowing the action
attribute to handle navigation only. The expression must evaluate to a public method that takes an ActionEvent
parameter, with a return type of void
.
Expand the Appearance section and set the following properties:
hoverIcon
: Enter the URI of the image file you want to display when the mouse cursor is directly on top of this toolbar button.
depressedIcon
: Enter the URI of the image file you want to display when the toolbar button is clicked.
Expand the Behavior section and set the actionDelivery
attribute. Set the attribute to none
if you do not want to fire an action event when the button is clicked. This is useful if you want the button to simply open a popup window. If set to none
, you must have a popup component in the popup
facet of the toolbar button (see Step 8), and you cannot have any value set for the action
or actionListener
attributes. Set to clientServer
attribute if you want the button to fire an action event as a standard command component
To have a toolbar button invoke a popup menu, insert a menu
component into the popup
facet of the commandToolbarButton
component. For information, see Section 14.2.1, "How to Create and Use Menus in a Menu Bar".
If you want a toolbar to stretch so that it equals the width of the containing parent component, set the stretchId
attribute on the toolbar to be the ID of the component within the toolbar that should be stretched. This one component will stretch, while the rest of the components in the toolbar remain a static size.
For example, in the File Explorer application, the inputText
component that displays the selected folder's name is the one that should stretch, while the outputText
component that displays the words "Current Folder" remains a static size, as shown in Example 14-4.
Example 14-4 Using the stretchId Attribute
<af:toolbar id="headerToolbar2" flex="2" stretchId="pathDisplay"> <af:outputText id="currLocation" noWrap="true" value="#{explorerBundle['menuitem.location']}"/> <af:inputText id="pathDisplay" simple="true" inlineStyle="width:100%" contentStyle="width:100%" binding="#{explorer.headerManager.pathDisplay}" value="#{explorer.headerManager.displayedDirectory}" autoSubmit="true" validator="#{explorer.headerManager.validatePathDisplay}"/> </af:toolbar>
You can also use the stretchId
attribute to justify components to the left and right by inserting a spacer
component, and setting that component ID as the stretchId
for the toolbar, as shown in Example 14-5.
Example 14-5 Using a Spacer to Justify Toolbar Components
<af:toolbar flex="1" stretchId="stretch1"> <af:commandToolbarButton text="Forward" icon="/images/fwdarrow_gray.gif" disabled="true"></af:commandToolbarButton> <af:commandToolbarButton icon="/images/uplevel.gif" /> <!-- Insert a stretched spacer to push subsequent buttons to the right --> <af:spacer id="stretch1" clientComponent="true"/> <af:commandToolbarButton text="Reports" /> <af:commandToolbarButton id="toggleRefresh" text="Refresh:OFF" /> </af:toolbar>
When a page with a toolbar is first displayed or resized, the space needed for each toolbar is based on the value of the toolbar's flex
attribute. The percentage of size allocated to each toolbar is determined by dividing its flex
attribute value by the sum of all the flex
attribute values. For example, say you have three toolbars in a toolbox, and those toolbars are grouped together to display on the same line. The first toolbar is given a flex
attribute value of 1
, the second toolbar also has a flex
attribute value of 1,
and the third has a flex
attribute value of 2
, giving a total of 4
for all flex
attribute values. In this example, the toolbars would have the following allocation percentages:
Toolbar 1: 1/4 = 25%
Toolbar 2: 1/4 = 25%
Toolbar 3: 2/4 = 50%
Once the allocation for the toolbars is determined, and the size set accordingly, each element within the toolbars are placed left to right (unless the application is configured to read right to left. For more information, see Section A.6.2.6, "Language Reading Direction"). Any components that do not fit are placed into the overflow list for the toolbar, keeping the same order as they would have if displayed, but from top to bottom instead of left to right.
Toolbars are supported and rendered by parent components such as panelHeader
, showDetailHeader
, and showDetailItem
, which have a toolbar
facet for adding toolbars and toolbar buttons to section headers and accordion panel headers.
Note the following points about toolbars at runtime:
A toolbar and its buttons do not display on a header if that header is in a collapsed state. The toolbar displays only when the header is in an expanded state.
When the available space on a header is less than the space needed by a toolbar and all its buttons, ADF Faces automatically renders overflow icons that allow users to select hidden buttons from an overflow list.
Toolbars do not render on printable pages.