• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

PrimeFaces AutoComplete + completeMethod Example

April 13, 2014 //  by Amr Mohammed//  Leave a Comment

Primefaces provides incredible amount of new components that adhered the different aspect of Ajax. One of the component AutoComplete is most widely used with the web applications. That component is AutoComplete which is a core primefaces component used for providing the user prompt suggestions while the input is being typed into the input box.

This tutorial should clarify the AutoComplete component once it filled using completeMethod strategy. In the completeMethod strategy, suggestions loaded by calling the server side completeMethod that takes a single string parameter which is the text entered.

  • Read : PrimeFaces Tutorials

1. AutoComplete Tag Info

AutmComplete General Info

2. AutoComplete Attributes

AutoComplete Attributes

3. Managed Bean

AutoComplete.java

package net.javabeat.primefaces;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class AutoComplete {
	private String message;

	public AutoComplete (){

	}

	public List<String> complete(String query){
		List<String> queries = new ArrayList<String>();
		for(int i = 0 ; i < 15 ; i++){
			queries.add(query+i);
		}
		return queries;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}

4. The View

index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
	<h:head>
		<script name="jquery/jquery.js" library="primefaces"></script>
	</h:head>
	<f:view>
		<h:form prependId="false">
			<h:outputText value="Type JavaBeat :"/>
			<p:autoComplete value="#{autoComplete.message}" completeMethod="#{autoComplete.complete}"></p:autoComplete>
		</h:form>
	</f:view>
</html>

5. Primefaces AutoComplete + completeMethod Demo

The below snapshot shows you the using of autoComplete primefaces component for rendering a suggestions for the end user that tries to type message.

AutoComplete Filling Suggestions Using completeMethod

[wpdm_file id=64]

Category: JSFTag: PrimeFaces

About Amr Mohammed

Previous Post: « Primefaces AjaxStatus Example
Next Post: PrimeFaces AutoComplete + POJO Example »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact