请问Primefaces排行榜需要帮助。在点击命令按钮后,应该使用Ajax加载基于下拉框中所选项目的不同图表。 问题是尽管正确设置了所选项目值,但图表不会更新。 在html和Managed Bean Code下面。
XHTML
<h:form>
<h:selectOneMenu value="#{chart.country}">
<f:selectItem itemValue="0" itemLabel="Item1" />
<f:selectItem itemValue="1" itemLabel="Item2" />
<f:selectItem itemValue="2" itemLabel="Item3" />
</h:selectOneMenu>
<p:commandButton value="View" update="votes" />
<p:chart id="votes" type="pie" model="#{chart.livePieModel}" style="width:400px;height:300px"/>
</h:form>
Java代码
private String country = "0";
private PieChartModel livePieModel = new PieChartModel();
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public PieChartModel getLivePieModel() {
if (Integer.parseInt(this.country) == 1)
refreshChart();
return livePieModel;
}
public void refreshChart() {
int random1 = (int) (Math.random() * 1000);
int random2 = (int) (Math.random() * 1000);
livePieModel.getData().put("Candidate 1", random1);
livePieModel.getData().put("Candidate 2", random2);
livePieModel.setTitle("Votes");
livePieModel.setLegendPosition("ne");
}