-2
I am trying to pass a Selectonemenu variable to a Chart of the first faces 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 in the 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.
my itemValue of <f:selectItem itemValue="#{login.user}"> serves to say that if it is blank it is the same as the logged in user. no <p:selectOneMenu> I’m already using value (not itemValue). the problem is that the variable #{bean.seller} is only set after the chart, and the chart is named null.
– Raphão Torres