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 the ItemSelect and ItemUnselect events

Let us see how to use the AutoComplete component's itemSelect and itemUnselect events:

  1. Create a form with the AutoComplete component and register the itemSelect and itemUnselect event listeners:
    <p:autoComplete id="newPostTags" value="#{postController.newPost.tags}" 
                    completeMethod="#{postController.completeTags}"
                    maxResults="10" minQueryLength="1" queryDelay="400" 
                    
                    var="t" itemLabel="#{t.label}" itemValue="#{t}" 
                    converter="tagConverter" multiple="true">
            <p:ajax event="itemSelect" listener="#{postController.handleTagSelected}"/>
            <p:ajax event="itemUnselect" listener="#{postController.handleTagUnselected}"/>
                    
    </p:autoComplete>
  2. Implement event listener methods: handleTagSelected() and handleTagUnselected() ...

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