primefaces Chart does not catch variable from SelectOneMenu

-2

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.

    
asked by anonymous 28.06.2016 / 15:57

1 answer

1

Next, when you use <p:selectOneMenu use value instead of itemValue to get the value that will be selected in the drop.

In your <f:selectItem you already pass a value to it ( itemValue="#{login.user}" ).

What you can do in this case is to use:

itemValue="valor"
    
28.06.2016 / 16:11