我在index.xhtml中显示了三个图表,表示来自数据表的数据。
在这样的数据表(在List.xhtml中)中插入一个寄存器之后,所有三个图表也应该立即更新,但只有2个按预期更新 - 顺便说一下,这两个barCharts。
pieChart已更新,但不会像其他两个barCharts一样立即更新,只会在重新启动Glassfish后或插入很长时间后更新。
为什么在数据表中插入新寄存器后,pieChart没有立即更新?我该如何解决这个问题?
遵循图表bean的代码摘录:
import br.com.bb.upb.diage.treinamentos.facades.UorPosFacade;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.primefaces.model.chart.PieChartModel;
@Named(value = "chartBeanUPB")
@RequestScoped
public class ChartBeanUPB implements Serializable {
@EJB
private UorPosFacade uf;
private PieChartModel modelChartBeanUPB;
//get and set ommited
private void TreinamentoUPBChart() {
modelChartBeanUPB = new PieChartModel();
//get data from database
modelChartBeanUPB.set("Orçado", orcData);
modelChartBeanUPB.set("Realizado", rlzData);
//another settings for the graphic
}
@PostConstruct
public void initialize() {
TreinamentoUPBChart();
}
@PreDestroy
public void cleanUp() {
}
}
摘录 index.xhtml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/WEB-INF/include/template.xhtml">
<ui:define name="title">
<h:outputText value="#{treinaBundle.AppName}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:form id="UPBChartFormId">
<p:accordionPanel multiple="false" activeIndex="false" >
<p:tab title="pieChart" >
<p:chart type="pie" id="treinamentosPie" model="#{chartBeanUPB.modelChartBeanUPB}" />
</p:tab>
<p:tab title="barChart 2" >
<p:chart type="bar" id="treinamentosBarGer" model="#{chartBeanGerencias.modelTreinamentosGer}" />
</p:tab>
<p:tab title="barChart 1" >
<p:chart type="bar" id="treinamentosBarDiv" model="#{chartBeanDivisoes.modelTreinamentosDiv}" />
</p:tab>
</p:accordionPanel>
</h:form>
</ui:define>
</ui:composition>
</html>
List.xhtml
除外<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:form id="TreinamentosListForm">
<p:panel id="idPanel" header="#{treinaBundle.ListTreinamentosTitle}" rendered="#{chave!=null}">
<p:dataTable id="datalist"
value="#{treinamentosController.items}"
var="item"
rowKey="#{item.id}"
selection="#{treinamentosController.selected}"
>
<p:ajax event="filter" process="@form" update="@this" listener="#{treinamentosController.onFilter}" />
<p:ajax event="rowSelect" update=":TreinamentosListForm:createButton :TreinamentosListForm:viewButton :TreinamentosListForm:editButton :TreinamentosListForm:deleteButton " listener="#{treinamentosController.resetParents}"/>
<p:ajax event="rowUnselect" update=":TreinamentosListForm:createButton :TreinamentosListForm:viewButton :TreinamentosListForm:editButton :TreinamentosListForm:deleteButton " listener="#{treinamentosController.resetParents}"/>
<p:ajax event="rowDblselect" onsuccess="document.getElementById('TreinamentosListForm:viewButton').click();"/>
<p:column>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column>
<h:outputText value="#{item.nomeCurso}"/>
</p:column>
<p:column>
<h:outputText value="#{item.valorCurso}" />
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</ui:composition>
提前致谢。