Primefaces users guide 3 5

Page 423

PrimeFaces User’s Guide public class TagCloudBean { private TagCloudModel model;

public TagCloudBean() { model = new DefaultTagCloudModel(); model.addTag(new DefaultTagCloudItem("Transformers", "#", 1)); //more } //getter

}

Selecting Tags An item is tagCloud can be selected using select ajax behavior. Note that only items with null urls can be selected. <h:form> <p:growl id="msg" showDetail="true" /> <p:tagCloud model="#{tagCloudBean.model}"> <p:ajax event="select" update="msg" listener="#{tagCloudBean.onSelect}" /> </p:tagCloud> </h:form>

public class TagCloudBean { //model, getter and setter

public void onSelect(SelectEvent event) { TagCloudItem item = (TagCloudItem) event.getObject(); FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", item.getLabel()); FacesContext.getCurrentInstance().addMessage(null, msg); }

}

TagCloud API org.primefaces.model.tagcloud.TagCloudModel Method

Description

List<TagCLoudItem> getTags()

Returns all tags in model.

void addTag(TagCloudItem item)

Adds a tag.

void removeTag(TagCloudItem item)

Removes a tag.

void clear()

Removes all tags. 423


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.