Page 1 of 1

autoComplete mouse click and enter key behave differently

Posted: 18 May 2017, 15:13
by m.mchugh
In this autoComplete, as the user enters characters, the selection list is populated as expected. If the user's only option were to select from the list generated, the Ajax for the change event could be eliminated and selection would work correctly whether the user clicked on the desired item or used the keyboard enter key to select it. In this case, however, the field may not narrow the selection list enough to make a selection so what the user types may also be used as the starting point for a lookup table. Think of a name search where the user is looking for a last name of Smith. To meet this requirement, both Ajax events, (change and itemSelect) must be present.

When the autoComplete contains both Ajax events, the behavior of the keyboard enter and the mouse click become different when selecting from the autoComplete selection list. If the desired item is highlighted on the list and the enter key is pressed, the itemSelect event is processed and the bean's selection process is executed correctly. If, however, the mouse is clicked, the change event is executed first and the itemSelect event is never executed.

Primefaces 5.2 and 6.1 both tested and found to be the same

HTML code:

Code: Select all

<p:column styleClass="dataEntryField">
		value="#{ssCgWebUserPassword0001.enteredWebUserId}" id="i0"
		autocomplete="off" maxlength="20" size="25" immediate="false"
		widgetVar="webId" maxResults="15" minQueryLength="1"
		<p:ajax update="i0, m0,:javaScriptResponseForm "
			listener="#{ssCgWebUserPassword0001.selectWebUserId}" />
		<p:ajax update="i0,m0, :javaScriptResponseForm" event="change"
			listener="#{ssCgWebUserPassword0001.editWebUserId}" />
	<p:message for="i0" id="m0" display="text" />
Java code:

Code: Select all

public List<String> completeWebIdLookup (String startingCharacters) {
	List<String> listOfIds = new ArrayList<>();
	listOfIds = webSecurityService.populateAutoCompleteList(startingCharacters);
	return listOfIds;

public void selectWebUserId () {
	selectedWebSecurity = webSecurityService.retrieveWebSecurityByWebUserId(enteredWebUserId);
	if (selectedWebSecurity == null || NumberUtil.isNullOrZero(
		selectedWebSecurity.getWebSecurityNtty().getWebSecuritySerial())) {
			super.getELEMENT_ID().f1_i0, MESSAGE_KEY.recordNotFound);
		selectedWebSecurity = new WebSecurityBO();
	} else {

public void editWebUserId() {
	// no edits

Re: autoComplete mouse click and enter key behave differently

Posted: 11 Jul 2017, 12:36
by m.mchugh
Have determined that mouse functionality can be restored by changing the Ajax change event as follows:

Code: Select all

<p:ajax update="i0,m0, :javaScriptResponseForm" event="change"
			onstart="if(PF('webId')':visible')) return false;"/>

Note that the term webId in the statement is the widget name for the autoComplete.