Question

What is the best way to implement a country autocomplete textfield in JSF2?

I would like to know if there are better ways than implementing a bean to inject a list of countries either from the database or an XML data source.

I am using the primefaces component library, would there be a ready-made plugin i could use?

Was it helpful?

Solution

You're going to need a managed bean anyway. Otherwise you can't reference it in JSF views. If the data is not subject to changes, just load and initialize it once in an application scoped bean. If the data needs to be refreshed on, for example, daily basis, make use of a @Singleton EJB with @Schedule and let your managed bean delegate to it.

PrimeFaces has a <p:autoComplete> component. You can find an example on their showcase. You can let the completeMethod point to the application scoped bean and point the value to the request/view scoped form bean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top