By Sonakshi Bajaj on Feb 20, 2013
The framework provided autosuggest behavior performs a “Starts with” search for displaying the values in the autoSuggest of an Input Combo Box List of Values. In this post, we will see how to implement a custom autosuggest behavior which returns values by performing a “contains” search.
The following image shows an input combo box list of values dropped on a .jsff:
We can add an autosuggest behavior from the Structure window by clicking af:inputComboBoxListOfValues -> Insert inside af:inputComboBoxListOfValues -> ADF Faces -> Auto Suggest Behavior
This is the autosuggest behavior provided by the framework which returns all values which START WITH the partial string typed by the user in the input combo box list of values. We will write a custom method in the backing bean which returns the values we want to show as follows:
As seen above, this method takes a String parameter which is the partial string entered by the user and it returns a List of SelectItems which have that string as a substring. The list is retrieved in the AMImpl as follows:
In this method, we get the VO which is used to populate the input combo box list of values and apply the following view criteria on it:
The bind variable ‘Bind_ResourceName’ is set to the partial string entered by the user. By applying the view criteria we get an iterator to all the rows matching this condition, i.e. all rows where the value of “DisplayName” contains the string entered by the user.
Finally, we use the custom method from the bean instead of the framework generated suggestedItems:
Now, when the user types in the input combo box list of values, all the values containing that partial string are displayed in the autosuggest as shown: