The ace:selectMenu component is an advanced selection component that behaves similarly to the <select> HTML element and provides a number of additional advantages like ajax support, ARIA support, label positions, Themeroller support and more flexibility in rendering the list. Option items are defined either by <f:selectItem> and <f:selectItems> tags or by using a custom facet to define a custom way of rendering the options, which can contain graphics and additional text, while separating that from the actual value of the option item.
|See the ICEfaces Showcase Live Demo of this component, complete with source code.|
In its simplest form, an ace:selectMenu component only requires to have some options defined and to bind its value to a property in a backing bean.
It is also possible to define how the list is to be rendered and to include arbitrary components in it. In order to do this, the listValue, listVar and itemValue attributes must be defined, as well as a facet named 'row', which will define the way the list is rendered.
|ace:comboBox vs. ace:selectMenu. The main difference between the ace:comboBox and the ace:selectMenu components is the autocomplete functionality of ace:comboBox. Use ace:selectMenu when the set of possible inputs is small and well-defined. Use ace:comboBox when you don't want to restrict the user from entering arbitrary input, but you still want to provide or suggest some common or expected pre-defined values for quickly selecting them.|
|topmost option item not selected by default. Another key difference between ace:selectMenu and ace:simpleSelectOneMenu (and h:selectOneMenu) is that ace:selectMenu doesn't select its topmost option item automatically upon loading. Because of this, ace:selectMenu can trigger validation errors if the form is submitted without the user having interacted with the component, whether 'required' is true or not. This is so because ace:selectMenu has the same validation logic as the other components, in which the submitted value has to match one of the f:selectItem options provided. If this behaviour is not desired, it can be avoided by simply adding an f:selectItem with an empty string value (<f:selectItem itemValue="" itemLabel="" />) as a child of the component. This can be done in addition to any other f:selectItem or f:selectItems tags already inside the component.|
This section covers attributes involved in the typical use-cases for this component. For reference, the complete taglib documentation for this component is available here.
|valueChange||Fired when the value of the menu changes.|
|blur||Fired when the menu loses focus.|
The client side component object is exposed through the global variable name specified in the widgetVar attribute.
|The ice.ace.instance function requires the full client id of the component to be specified, such as "j_idt77:componentId" instead of just "componentId". To reduce the complexity of working with complete IDs with this function it may be preferable in some cases to use prependId="false" in the enclosing form (e.g. <h:form prependId="false">).|
Full ARIA support. Arrow keys supported to navigate options up and down. Keyboard acceleration supported (after typing a character the first item that starts with such character is highlighted).
The following ARIA roles are supported: select, option.
It is possible to customize the way in which the option items are displayed by means of the 'row' facet. You can add any arbitrary content, and if some of that content is only there for presentation purposes and is not part of the value string, you can use the ui-selectmenu-item-ignore CSS class to ignore that text. In the example below, a color box is created with CSS, and an underscore character is used only to give some width to the box; since this character is not part of the value string, we add the ui-selectmenu-item-ignore CSS class to it.
This component supports built-in labels. The text specified in the label attribute will be rendered next to the main input field of this component. The position specified by labelPosition will determine where this label is going to be rendered; the possible values are left, right, top, bottom, none and inField (to render the label in the field itself).
The requiredIndicator attribute specifies the text to be displayed next to the main input field when this component is marked as required. When, this component is not marked as required, then the text specified in the optionalIndicator is going to be rendered. The indicatorPosition attribute determines where this indicator text is going to the rendered; the possible values are left, right, top, bottom, labelLeft, labelRight, and none.
Then this component is marked as required, the main input field receives the CSS class ui-state-required, otherwise, it receives the CSS class ui-state-optional. When this component is marked as invalid by the app, it will be rendered with the CSS class ui-state-error. These CSS classes can be used to add custom styling to this component, in order indicate its current state in a more visual way.
The following markup represents the basic HTML structure of the component and the CSS classes it uses.
Additionally, the ui-selectmenu-item-ignore class name can be added when using the component in facet mode to components and elements that are rendered for display purposes but that are not part of the value that is submitted to the server.