I'm trying to pass a SelectOneMenu variable to a Chart of primefaces and I believe the program updates the Chart before passing the variable.
<p:outputLabel for="listagem" value="Vendedores:" />
<p:selectOneMenu id="listagem"
value="#{bean.vendedor}"
style="width:125px" >
<f:selectItem itemLabel="Selecione" itemValue="#{login.user}" />
<f:selectItems value="#{bean.vendedores}" />
</p:selectOneMenu>
<p:commandButton value="Pesquisar" oncomplete="#{bean.refreshChart()}" update="myBarChart"/>
</h:panelGrid>
<form>
<p:chart type="pie" model="#{bean.model}" id="myBarChart">
<p:ajax event="itemSelect" listener="#{bean.itemSelect}" />
</p:chart>
</form>
and no bean;
@ManagedBean
public class Bean {
private PieChartModel model;
private String vendedor;
private List<String> vendedores;
public List<String> getVendedores() throws SQLException {
GestorVisaoVendedorDAO dao = new GestorVisaoVendedorDAO();
vendedores = dao.vendedoresAtivos();
return vendedores;
}
public void setVendedores(List<String> vendedores) {
this.vendedores = vendedores;
}
public String getVendedor() {
return vendedor;
}
public void setVendedor(String vendedor) {
this.vendedor = vendedor;
}
public void refreshChart() {
criaGrafico();
}
public Bean() {
criaGrafico();
}
public void criaGrafico() {
model = new PieChartModel();
model.set(vendedor, 540);
model.set("Brand 2", 325);
model.set("Brand 3", 702);
model.set("Brand 4", 421);
model.setTitle("Simple Pie");
model.setLegendPosition("w");
}
public PieChartModel getModel() {
return model;
}
public void itemSelect(ItemSelectEvent event) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item selected",
"Item Index: " + event.getItemIndex() + ", Series Index:" + event.getSeriesIndex());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
It's a ready-made prime table just to simplify the problem.