Let us see how we can create a TagCloud component and initialize it with some sample Tag data.
Create the
TagCloud
component using<p:tagCloud>
:<p:tagCloud model="#{tagController.model}"/>
Create the
TagCloudModel
object and populateTagCloudItem
:public class TagController { private TagCloudModel model; public TagController() { model = new DefaultTagCloudModel(); model.addTag(new DefaultTagCloudItem("PrimeFaces", "/posts.jsf?tag=primefaces",5); model.addTag(new DefaultTagCloudItem("JSF", "#",3); model.addTag(new DefaultTagCloudItem("jQuery",2); } }
We have created a TagCloudModel
object using DefaultTagCloudModel
and populated TagCloudItem
with various labels
, urls
, and strengths
. For the "PrimeFaces"
tag we provided the URL relative to our application path "/posts.jsf?tag=primefaces"
. The URL is optional; its default value is "#"
.
TagCloud supports the select
AJAX event. Only tags where URL...