java PrimeFaces图表未使用Ajax请求更新
求你了,我需要你的帮助。使用Ajax,它应该在单击命令按钮后根据下拉框中的选定项加载不同的图表。 问题是,尽管所选项目值设置正确,但图表未更新。 下面是html和托管Bean代码
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");
}
共 (0) 个答案