6.47.  < rich:menuItem >

6.47.1. Description

The <rich:menuItem> component is used for the definition of a single item inside a pop-up list.

<rich:menuItem> component

Figure 6.84.  <rich:menuItem> component


6.47.2. Key Features

  • Highly customizable look-and-feel

  • Different submission modes

  • Support for disabling

  • Custom content support

Table 6.177. rich : menuItem attributes

Attribute NameDescription
actionMethodBinding pointing at the application action to be invoked, if this UIComponent is activated by you, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property
actionListenerMethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingleif "true", submits ONLY one field/link, instead of all form controls
bindingThe attribute takes a value-binding expression for a component property of a backing bean
bypassUpdatesIf "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
disabledIf "true" sets state of the item to disabled state. "false" is default
eventsQueueName of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.)
focusid of element to set focus after request completed on client side
iconPath to the icon to be displayed for the enabled item state
iconClassClass to be applied to icon element
iconDisabledPath to the icon to be displayed for the disabled item state.
iconStyleCSS style rules to be applied to icon element
idEvery component may have a unique id that is automatically created if omitted
ignoreDupResponsesAttribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
immediateTrue means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase
labelClassClass to be applied to label element
limitToListIf "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components
onbeforedomupdateJavaScript code for call before DOM has been updated on client side
onclickHTML: a script expression; a pointer button is clicked
oncompleteJavaScript code for call after request completed on client side
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
onselectHTML: script expression; The onselect event occurs when you select some menu item
processId['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
renderedIf "false", this component is not rendered
requestDelayAttribute defines the time (in ms.) that the request will be wait in the queue before it is ready to send. When the delay time is over, the request will be sent to the server or removed if the newest 'similar' request is in a queue already
reRenderId['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
selectClassClass to be applied to selected items
selectStyleCSS style rules to be applied to selected items
statusID (in format of call UIComponent.findComponent()) of Request status component
styleCSS style(s) is/are to be applied when this component is rendered
styleClassCorresponds to the HTML class attribute
submitModeSet the submission mode (ajax, server(Default), none)
targetName of a frame where the resource retrieved via this hyperlink is to be displayed
timeoutResponse waiting time on a particular request. If a response is not received during this time, the request is aborted
valueThe current value for this component

Table 6.178. Component identification parameters

NameValue
component-typeorg.richfaces.MenuItem
component-classorg.richfaces.component.html.HtmlMenuItem
component-familyorg.richfaces.DropDownMenu
renderer-typeorg.richfaces.MenuItemRenderer
tag-classorg.richfaces.taglib.MenuItemTag

6.47.3. Creating the Component with a Page Tag

Here is a simple example as it could be used on a page:

Example:


...
    <rich:dropDownMenu>
        ...
        <rich:menuItem value="Active"/>
        ...
    <rich:dropDownMenu>
...

6.47.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.HtmlMenuItem;   
...
HtmlMenuItem myMenuItem = new HtmlMenuItem();
...

6.47.5. Details of Usage

The "value" attribute defines the text representation for an item element.

There are two icon-related attributes. The "icon" attribute defines an icon. The "iconDisabled" attribute defines an icon for a disabled item. Also you can use the "icon" and "iconDisabled" facets. If the facets are defined, the corresponding "icon" and "iconDisabled" attributes are ignored and the facets content is shown as an icon. It could be used for an item check box implementation.

Here is an example:


...
    <f:facet name="icon">
        <h:selectBooleanCheckbox value="#{bean.property}"/>
    </f:facet>
...

The <rich:menuItem> "submitMode" attribute can be set to three possible parameters:

  • Server (default)

Regular form submission request is used.

  • Ajax

Ajax submission is used for switching.

  • None

The "action" and "actionListener" item's attributes are ignored. Menu items don' fire any submits themselves. The behavior is fully defined by the components nested into items.

For example, you can put any content into an item, but, in this case, you should set the "mode" attribute as "none" .

Here is an example:


...
    <rich:dropDownMenu>
        ...
        <rich:menuItem submitMode="none">
            <h:outputLink value="www.jboss.org"/>
        </rich:menuItem>
        ...
    <rich:dropDownMenu>
...

You can use the "disabled" attribute to set the item state.

Here is an example:


...
    <rich:dropDownMenu>
        <rich:menuItem value="Disable" disabled="true"/>
    <rich:dropDownMenu>
...

Note:

The <rich:menuItem> component was designed to be used only for pop-up menu list creation.

Information about the "process" attribute usage you can find here.

6.47.6. Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:menuItem> components at once:

  • Redefine the corresponding skin parameters

  • Add to your style sheets style classes used by a <rich:menuItem> component

6.47.7. Skin Parameters Redefinition

Table 6.179. Skin parameters redefinition for an item

Skin parametersCSS properties
generalFamilyFontfont-family
generalSizeFontfont-size

Table 6.180. Skin parameters redefinition for a hovered item

Skin parametersCSS properties
tipBorderColorborder-color
tipBackgroundColorbackground-color

Table 6.181. Skin parameters redefinition for a disabled item

Skin parametersCSS properties
tabDisabledTextColorcolor

Table 6.182. Skin parameters redefinition for a label

Skin parametersCSS properties
generalTextColorcolor

6.47.8.  Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Classes names

Figure 6.85. Classes names


Table 6.183. Classes names that define an appearance of item elements

Class nameDescription
rich-menu-itemDefines styles for a wrapper <div> element for an item
rich-menu-item-labelDefines styles for a label of an item
rich-menu-item-iconDefines styles for the left icon of an item

Table 6.184. Classes names that define different states

Class nameDescription
rich-menu-item-disabledDefines styles for a wrapper <div> element of an item
rich-menu-item-enabledDefines styles for a wrapper <div> element of an enabled item
rich-menu-item-hoverDefines styles for a wrapper <div> element of a hover item
rich-menu-item-label-disabledDefines styles for a label of a disabled item
rich-menu-item-icon-disabledDefines styles for the left icon of a disabled item
rich-menu-item-label-enabledDefines styles for a label of an enabled item
rich-menu-item-icon-enabledDefines styles for the left icon of an enabled item
rich-menu-item-label-selectedDefines styles for a label of a selected item
rich-menu-item-icon-selectedDefines styles for the left icon of a selected item

In order to redefine styles for all <rich:menuItem> components on a page using CSS, it's enough to create classes with the same names and define necessary properties in them.

To change styles of particular <rich:menuItem> components, define your own style classes in the corresponding <rich:menuItem> attributes.

6.47.9. Relevant Resources Links

Here you can see the example of <rich:menuItem> usage and sources for the given example.