我有以下评分代码:
<h:form>
<p:growl id="messages" showDetail="true"></p:growl>
<h:outputLabel value="Rating:" />
<p:rating value = "#{ratingBean.rating}" stars="5" rendered="true">
<p:ajax event="rate" listener="#{ratingBean.onrate}" update="messages" />
</p:rating>
</h:form>
我的支持豆是这样的:
包备份控制器;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import org.primefaces.event.RateEvent;
@Named
@RequestScoped
public class RatingBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Integer getRating() {
System.out.println("You Rated: "+ rating);
return rating;
}
public void setRating(Integer rating) {
this.rating = rating;
System.out.println("You Rated re:");
}
public void onrate(RateEvent rateEvent) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Rate Event", "You rated:" + ((Integer) rateEvent.getRating()).intValue());
FacesContext.getCurrentInstance().addMessage(null, message);
}
// public void oncancel() {
// FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cancel Event", "Rate Reset");
//
// FacesContext.getCurrentInstance().addMessage(null, message);
// }
private Integer rating;
}
我收到了我已评级的信息消息,但在控制台中,该值被评为 null。在我的 xhtml 页面上显示信息以及评级,但 bean 没有读取值。