autoComplete mouse click and enter key behave differently

UI Components for JSF
Post Reply
m.mchugh
Posts: 6
Joined: 11 Feb 2012, 13:34

18 May 2017, 15:13

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">
	<p:autoComplete
		value="#{ssCgWebUserPassword0001.enteredWebUserId}" id="i0"
		autocomplete="off" maxlength="20" size="25" immediate="false"
		widgetVar="webId" maxResults="15" minQueryLength="1"
		queryDelay="300"
		completeMethod="#{ssCgWebUserPassword0001.completeWebIdLookup}">
		<p:ajax update="i0, m0,:javaScriptResponseForm "
			event="itemSelect"
			listener="#{ssCgWebUserPassword0001.selectWebUserId}" />
		<p:ajax update="i0,m0, :javaScriptResponseForm" event="change"
			listener="#{ssCgWebUserPassword0001.editWebUserId}" />
	</p:autoComplete>
	<p:message for="i0" id="m0" display="text" />
</p:column>
,
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())) {
		FacesContextUtil.createErrorMessage(
			super.getELEMENT_ID().f1_i0, MESSAGE_KEY.recordNotFound);
		focusOn(super.getELEMENT_ID().f1_i0_input);
		selectedWebSecurity = new WebSecurityBO();
		return;
	} else {
		super.getConversation().setAttribute(super.getCONVERSATION_KEY().selectedWebSecurity,
				selectedWebSecurity);
		FacesContextUtil.redirect(LINK.ssCgWebUserPassword0002);
	}
}

public void editWebUserId() {
	// no edits
}

MikeInLenexa
PF 5.2
JSF 2.2.12
Wildfly 10.0 final
Java jdk 8

m.mchugh
Posts: 6
Joined: 11 Feb 2012, 13:34

11 Jul 2017, 12:36

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"
			listener="#{ssCgWebUserPassword0001.editWebUserId}" 
			onstart="if(PF('webId').panel.is(':visible')) return false;"/>

Note that the term webId in the statement is the widget name for the autoComplete.
MikeInLenexa
PF 5.2
JSF 2.2.12
Wildfly 10.0 final
Java jdk 8

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests