Rating component provides a star based rating input.
<div class="card">
<h:form>
<p:growl id="messages" showDetail="true"/>
<h5 class="mt-0">Basic</h5>
<p:rating id="rating1" value="#{ratingView.rating1}"/>
<h5>Remote</h5>
<p:rating id="rating2" value="#{ratingView.rating2}">
<p:ajax event="rate" listener="#{ratingView.onrate}" update="messages"/>
<p:ajax event="cancel" listener="#{ratingView.oncancel}" update="messages"/>
</p:rating>
<h5>Readonly</h5>
<p:rating id="ratingReadOnly" value="#{ratingView.rating3}" readonly="true"/>
<h5>Disabled</h5>
<p:rating id="ratingDisabled" value="#{ratingView.rating3}" disabled="true"/>
<h5>Required</h5>
<div class="flex flex-col gap-2">
<p:rating id="rating4" value="#{ratingView.rating4}" required="true" requiredMessage="Please rate us!" />
<p:commandButton value="Rate" action="#{ratingView.onSubmit}" update="@form" process="@this rating4" />
</div>
</h:form>
</div>
@Named
@RequestScoped
public class RatingView {
private Integer rating1;
private Integer rating2;
private Integer rating3 = 4;
private Integer rating4;
public void onrate(RateEvent<Integer> rateEvent) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Rate Event", "You rated:" + rateEvent.getRating());
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void oncancel() {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cancel Event", "Rate Reset");
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void onSubmit() {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Submitted", "You rated:" + rating4);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public Integer getRating1() {
return rating1;
}
public void setRating1(Integer rating1) {
this.rating1 = rating1;
}
public Integer getRating2() {
return rating2;
}
public void setRating2(Integer rating2) {
this.rating2 = rating2;
}
public Integer getRating3() {
return rating3;
}
public void setRating3(Integer rating3) {
this.rating3 = rating3;
}
public Integer getRating4() {
return rating4;
}
public void setRating4(Integer rating4) {
this.rating4 = rating4;
}
}