Time for action – using the Rating component
Let us see how we can use the Rating component with 10 stars and use the rate
and cancel
AJAX event listeners:
- Create a Rating component and register the AJAX listeners for the
rate
andcancel
events, using the following code:<p:growl id="growl"/> <p:rating value="#{postController.selectedPost.rating}" stars="10"> <p:ajax event="rate" listener="#{postController.handlePostRating}" update="growl" /> <p:ajax event="cancel" listener="#{postController.handlePostRatingCancel}" update="growl" /> </p:rating>
- Implement the event listener methods:
@ManagedBean @RequestScoped public class PostController { private Post selectedPost; //setters and getters public void handlePostRating(RateEvent rateEvent) { Integer rate = (Integer) rateEvent.getRating(); JSFUtils.addInfoMessage("Post rated:...