O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using AutoComplete with POJO support

Let us see how we can use List<Tag> objects to populate the AutoComplete component:

  1. Create the Search Posts form with the AutoComplete component:
    <p:autoComplete value="#{postController.searchTag}" 
                    completeMethod="#{postController.completeTag}"
                    var="t" itemLabel="#{t.label}" itemValue="#{t}" 
                    converter="tagConverter"/>
  2. Implement the completeMethod handler method and the completeTag() method returning the List<Tag> object:
    public List<Tag> completeTag(String query) { if(query == null){ return new ArrayList<Tag>(); } List<Tag> tags = new ArrayList<Tag>(); List<Tag> allTags = loadTagsFromDataSource(); for (Tag tag : allTags) { if(tag.getLabel().toLowerCase().startsWith(query.toLowerCase())) { tags.add(tag); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required