There a few simple steps required to take advantage of ICEfaces 2 in your JSF 2 application.
Adding the icefaces.jar to your project immediately allows you to take advantage of our Direct-to-DOM (D2D) rendering technology. D2D only sends browser DOM changes from the server to the browser, minimizing bandwidth consumption without the need to specify the new "f:ajax" component in your pages.
Once the icefaces.jar is added to your project, you can also take advantage of ICEfaces Window Scope and Single Submit features.
ICEfaces 2 provides a compatible component library based on the ICEfaces 1.x component suite. This set of components are referred to as "ICEfaces Components" and immediately allow developers to build ICEfaces 2 applications give the developer access to a mature AJAX component suite.
Unable to render embedded object: File (autocomplete-main.png) not found.
To get auto-complete functionality we use the ice:selectInputText component. This component is displayed like a regular inputText component but adds auto-complete functionality.
The ice:selectInputText component can generate one of two types of lists:
- A list of String data
- A list of arbitrarily complex child components
The following code sample shows an implementation using a list of String data:
This will display a drop-down list of cities that match the text input. The 'rows' attribute defines how many results will be returned when text is entered. The 'width' attribute sets the width of the input text box and the drop-down list. The 'valueChangeListener' attribute binds to a backing bean method that determines the associated list when a value is changed.
Nested in the ice:selectInputText component tag is an f:selectItems JSF tag. The 'value' binding in this tag provides the list of available options. The screen shot below shows the component in action:
Unable to render embedded object: File (autocomplete-action.png) not found.
The following code sample shows an implementation with a list of arbitrarily complex child components:
This will display values similar to the first way but adds more information to the drop down menu, such as state and zip, in addition to the city. The screen shot below shows this method in action:
Unable to render embedded object: File (autocomplete-action2.png) not found.
In the application we use three main backing beans:
- AutoCompleteBean: Stores the values gathered from the AutoCompleteDictionary class. Also contains utility methods for updating the list and getting the matches from the dictionary list.
- AutoCompleteDictionary: Gets the dictionary list from a file in the file system. Also sorts the dictionary appropriately.
- City: Basic class used as an object in the dictionary list.
The backing beans retrieve lists of viable options from AutoCompleteDictionary. Our dictionary is populated from an xml file as follows:
In this case, we have encapsulated the options available to the user in a zipped xml file that is deployed with the applications. Options available to the user could also be retrieved from a database.
|autocomplete-tutorial||[autocomplete-tutorial source code|^autocomplete-tutorial.zip|Download Source Code]||Simple example on how to use the Auto-Complete component.|