See Also
You can drag the Standard JavaServer Faces Listbox component
from
the Palette to the Visual Designer to create a component that
enables the user to select one item from a list of items. If
the box is too small to contain the items in the list, the list
box includes scrollbars. Only one item at a time can be selected.
If you want a listbox in which multiple items can be selected,
use the Basic Listbox component.
- This component is a JavaServer Faces reference implementation that cannot use themes. The Listbox component in the Basic category of the Palette does support themes and provides other features that improve ease of use, such as your choice of a multple selection or a single selection list.
A Listbox is a composite component: the enclosing component
(listbox) manages the style and behavior of the list itself,
and the inside component (listboxSelectItems) is used to bind
to the actual items in the list. A third, related component
named listboxDefaultItems is created for each Listbox component
that you add to the page and contains an array of static default
items for the list (item1, item2, item3).
This last component is not one that you typically work with.
You can see all these components in the Outline window after you add a Listbox to your page.
A Listbox renders as an HTML <select> tag with
the size attribute set to a value greater than 1.
After adding a Listbox Component to a page, you can do a number
of things with it:
- Select the component and drag it to another location on
the page.
- Drag a table from the Servers window and drop it on the
component, and then choose whether to fill the list with the
table data or set the component up to have its selection driven
by another component. For more information, see Binding a List Component to a Database.
- Select the component and edit its properties in the Listbox
property
sheet. Some typical properties you might set are:
- id. The name of the Listbox component. In the
JSP file, this name is the value of the component's id
attribute. In the page bean, this property's value is
the name of the HtmlSelectOneList object.
- size. The number of options to show at one time.
If there are more options to show than indicated in this
property, a scrollbar is added to the listbox. If this
property is not set, all options are shown.
- value. Actually, you do not usually set this
property. The value property is not rendered on the screen,
but is used when the form is submitted to send the currently
selected list element. The list displayed in the component
is controlled by the listboxSelectItems part
of the component, not by the value property. See the Fill
List From Database selection's description below for a
typical way to set the listboxSelectItems part
of the component.
- Right-click the component and choose one of the following
pop-up menu items:
- Edit Event Handler. Write code for one of the
following event handlers.
- validate. Opens the Java Editor with the
cursor positioned in the component's validate
method so you can insert code to validate the value
of the component.
- processValueChange. Opens the Java Editor
with the cursor positioned in the component's processValueChange
method so you can insert code that executes when the
value of this component changes (for example, the
user changes the value of another component that is
controlling the value of this component).
- Bind to Data. Opens a dialog box that
enables you to bind the component to an object or data provider that will update the list dynamically. For example, you might
choose this option rather than dropping a table on the
component if a database table has already been added to
the page. For more information, see Bind to Data Dialog Box.
- Auto-submit on Change. Causes the form to be automatically submitted if the value of the component changes. Sets the component's JavaScript onclick property to
common_timeoutSubmitForm(this.form, 'component-id');. At runtime, this code causes the form to be automatically submitted if the user changes the component value. Once the form is submitted, conversion and validation occur on the server and any value change listener methods execute, and then the page is redisplayed.
A component configured to Auto-submit on Change can use virtual forms to limit the input fields that are processed when the form is submitted. If the auto-submit component is defined to submit a virtual form, only the participants in that virtual form will be processed when the auto-submit occurs.
- Configure Virtual Forms. Enables you to add the component to a virtual form.
- Property Bindings. Opens a dialog box that enables
you to bind the properties of the component to other objects
or properties that can update this component's properties
automatically.
- See Also
- Working
With Components
- Component
Tasks: Quick Reference
- Component
Web Tutorials
- Data
Source Web Tutorials
- About the Palette