Star-based rating input
The rating
component provides star-based rating with the ability to select and cancel.
How to do it...
The basic declaration for the component would be as follows:
<p:rating value="#{ratingController.rate}" />
Here rate
is a java.lang.Integer
definition. The default visual of the component will be as shown in the following screenshot:
The stars
attribute sets the number of stars to display with a default value 5
.
There's more...
It is also possible to invoke a server-side method instantly when the user rates or cancels the rating. The rating
component provides two AJAX behavior events for this, rate
and cancel
.
A sample definition that updates the growl
component would be as follows:
<p:rating id="instantRating" value="#{ratingController.rate}"> <p:ajax event="rate" listener="#{ratingController.handleRate}" update="growl" /> <p:ajax event="cancel" listener="#{ratingController.cancelRate}" update="growl" /> </p:rating>
The handleRate
method...