How to load a chart after the selected date? I'm using JSF with PrimeFaces Chart

0

I want to load the chart as soon as the date is selected, but I can not get the date value. NOTE: The date is null, giving NPE (Null Pointer Excpetion) And my buttomCommand is only working as a test, to see if it enters the method

XHTML:

<ui:define name="cont_principal">


    <div class="col-md-12" style="margin-top: 0.4%;">
        <div id="lateral" class="col-md-2">
            <div class="vertical-menu">
                <a href="#"><span class="fa fa-plug" /> Serial</a> <a href="#"><span
                    class="glyphicon glyphicon-play" /> Start</a> <a href="#"><span
                    class="glyphicon glyphicon-stop" /> Stop</a> <a href="#">Test</a> <a
                    href="#"><span class="glyphicon glyphicon-file" /> Generate</a> <a
                    href="#"><span class="glyphicon glyphicon-expand" /> CSV</a> <a
                    href="#"><span class="glyphicon glyphicon-expand" /> MDB</a>
            </div>
        </div>
        <h:form>
            <p:growl id="growl" life="2000" />
            <p:calendar navigator="true" value="#{chartView.data}" locale="pt_BR" 
                pattern="dd/MM/yyyy" id="data" class="dtchoice" /> 
            <p:commandButton actionListener="#{chartView.buttonAction}" id="iconOnly" update="growl" icon="ui-icon-disk" title="Icon Only" />

            <div id="telas" class="col-md-10">
                <h:panelGrid columns="2" columnClasses="left,right" style="width:100%">
                    <p:chart type="bar" model="#{chartView.animatedModel2}" style="width:400px;" />
                </h:panelGrid>
            </div>
        </h:form>

    </div>




</ui:define>

CONTROLLER:

@ManagedBean
public class ChartView implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private BarChartModel animatedModel2;
    private Date data;
    private GraficoDAO dao;

    @PostConstruct
    public void init() {        
        createAnimatedModels();
    }

    private void createAnimatedModels() {
        animatedModel2 = initBarModel();
        animatedModel2.setTitle("Veículos pesados por dia");
        animatedModel2.setAnimate(true);
        animatedModel2.setLegendPosition("ne");
    }

    public BarChartModel initBarModel() {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String data = df.format(getData());
        setData(getData());

        try {
            dao = new GraficoDAO();
            int aux1 = dao.getVehiclePerDay(data);
            int aux2 = dao.getOthersPerDate(data);

            BarChartModel model = new BarChartModel();

            ChartSeries vPesados = new ChartSeries();
            vPesados.setLabel("Pesados");
            vPesados.set("Veículos Pesados", aux1);
            ChartSeries vOutros = new ChartSeries();
            vOutros.setLabel("Outros");
            vOutros.set("Outros", aux2);

            model.addSeries(vPesados);
            model.addSeries(vOutros);


            return model;

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public void buttonAction(ActionEvent actionEvent) {
        addMessage();
    }

    public void addMessage() {
        System.out.println("//////////////////");

    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public BarChartModel getAnimatedModel2() {
        return animatedModel2;
    }

}
    
asked by anonymous 21.09.2018 / 17:32

0 answers