Time for action – using basic AutoComplete
Let us see how to use the AutoComplete component in the Search Users screen to display a list of matching e-mail IDs:
Create a Search Users form with the AutoComplete component to search by e-mail ID:
<h:form id="searchUserForm"> <h:panelGrid columns="2"> <p:outputLabel for="searchUser" value="Search Users By Email"/> <p:autoComplete id="searchUser" value="#{userController.searchEmail}" completeMethod="#{userController.completeEmail}"/> <p:commandButton action="${userController.searchUsers()}" value="Submit" update="@form"/> </h:panelGrid> </h:form>
Implement the
completeEmail()
method to provide suggestions:public List<String> completeEmail(String query) { List<String> emails = new ArrayList<String>(); List<User> users = userService.findAllUsers(); for (User user : users) { if(user...