Tips & Tricks from Arun on JDev ADF, Forms, SQL & PL/SQL.

Restrict number of characters to be typed for af:autoSuggestBehavior

When using AutoSuggestBehavior for a UI Component, the auto
suggest list is displayed as soon as the user starts typing in the
field. In this article, we will find how to restrict the
autosuggest list to be displayed till the user types in couple of
characters.

This would be more useful in the low latency networks and also
the autosuggest list is bigger. We could display a static message
to let the user know that they need to type in more characters to
get a list for picking a value from. Final output we would expect
is like the below image

Lets see how we can implement this. Assuming we have an input
text for the users to enter the country name and an autosuggest
behavior is added to it.

Also, assuming we have a VO (we'll name it as CountryView for this
example), with a view criteria to filter out the VO based on the
bind variable passed.

Now, we would generate View Impl class from the java node
(including bind variables) and then expose the setter method of the
bind variable to client interface.

In the View layer, we would create a tree binding for the VO and
the method binding for the setter method of the bind variable
exposed above, in the pagedef file

As we've already added an input text and an autosuggestbehavior
for the test, we would not need to build the suggested items for
the autosuggest list.Let us add a method in the backing bean to
return us List of select items to be bound to the autosuggest
list.

So, what we are doing in the above method is, to check the
length of the search term and if it is more than 1 (i.e 2 or more
characters), the return the actual suggest list. Otherwise, create
a read only select item

new SelectItem("","Type in two or more characters..","",true);

and add it to the list of suggested items to be displayed. The
last parameter for the SelectItem (boolean) is to make it as
readOnly, so that users would not be able to select this static
message from the displayed list.

i used your code but when the search pop up list shows up after i write 3+ letters, its shows me ALWAYS the first 20 rows, no matter what i write in the search text bob. Any chance you face the same problem? or can you help me solve this please?