-
1. Re: RF4 rich:autoComplete with ENTER to start search
healeyb Nov 3, 2011 9:45 PM (in response to edilmar)But why do you have to press enter, it's an autocomplete component after all?
-
2. Re: RF4 rich:autoComplete with ENTER to start search
edilmar Nov 4, 2011 8:40 AM (in response to healeyb)Because I use autoComplete in database tables with more than 50.000 records, for example, in a client or employee table.
Then, the user would type part of the client name, press ENTER and process the search.
If I use the default behaviour, after minimal characters typed, at each new char the search is run, and this becomes very slow.
-
3. Re: RF4 rich:autoComplete with ENTER to start search
healeyb Nov 5, 2011 7:45 AM (in response to edilmar)I'm not particularly hopeful that it will work, but you could try autofill="false"... More importantly though
rich:autocomplete mode="cachedAjax" "In this mode the component requests data when the minimum
number of characters is entered, but doesn't make additional requests if the prefix does not change" -
this is from Pratical Richfaces 2. the lazyClient mode is also worth investigating.
With a bit of luck, what will happen is that you type in minChars characters, the component requests
data from the server, and then when you type in additional characters the extra filtering will be done on
the client side, but with only one request. I appreciate that you don't want half a million rows getting
moved about every time someone hits a key. You could check this using firebug/dev tools or put a log
in the autocompleteMethod.
When I last looked autocomplete didn't have pojo support (i.e. var= itemLavbel= itemValue=) so I wrote
my own custom component (which incidentally does make a new request every time someone hits a
key!), I must go back and have a look at the latest version.
Regards,
Brendan.
-
4. Re: RF4 rich:autoComplete with ENTER to start search
edilmar Nov 7, 2011 9:24 AM (in response to healeyb)I had this in primefaces p:autoComplete:
- queryDelay="60000" => I never want to use default search;
- onkeypress="if (isEnter(event)) {employeeAutoComplete.search(employeeAutoComplete.value);}".
Then, I test onkeypress for ENTER key. If it's true, I call search method from p:autoComplete.
The main problem with rich:autocomplete is the absence of queryDelay property (to disable automatic search) and a way to call a search method from ENTER keypress event.
-
5. Re: RF4 rich:autoComplete with ENTER to start search
edilmar Nov 7, 2011 3:37 PM (in response to edilmar)I got to create onkeypress to test ENTER and to run something. I simulated requestDelay changing minChars to 1000, just to it doesn't run anything automatically. The problem now is... what is the rich:autocomplete method to call that works like p:autocomplete.search() ?
-
6. Re: RF4 rich:autoComplete with ENTER to start search
edilmar Nov 8, 2011 3:10 PM (in response to edilmar)Hi,
I solved my problem in this way:
1) I inserted an onkeypress event into my rich:autocomplete comp:
onkeypress="return enterToAutoComplete('myautocompletecompname', 5, event);"
2) This is the enterToAutoComplete event:
function enterToAutoComplete(objName, minChars, evtKeyPress) {
var input = document.getElementById(objName);
var autocomplete = input.rf.component;
var nTecla = evtKeyPress.keyCode;
if (nTecla == 13) {
autocomplete.options.minChars = minChars;
autocomplete.isFirstAjax = true;
autocomplete.__updateState(evtKeyPress);
autocomplete.options.minChars = 100;
return false;
}
else
return true;
}
Then, I handled some rich:autocomplete properties to update the state when ENTER is pressed, and I never use default search behaviour with minChars.