I am trying to use the ChartBean
sample from PrimeFaces. This is the view:
<h:form>
<p:layoutUnit position="center">
<p:lineChart id="linear" value="#{chartBean.linearModel}" legendPosition="e"
title="Linear Chart" minY="0" maxY="1000" style="height:600px"/>
</p:layoutUnit>
</h:form>
This is the bean:
@Named
@RequestScoped
public class ChartBean implements Serializable {
private CartesianChartModel categoryModel;
private CartesianChartModel linearModel;
public ChartBean() {
System.out.println("ChartBean constructed");
createCategoryModel();
createLinearModel();
}
// ...
}
While I run it, I noticed that the constructor of this bean is invoked twice while opening the page. The logs shows the following:
INFO: ChartBean constructed
INFO: ChartBean constructed
So the bean was instantiated twice. How is this caused and how can I avoid that? I'm interacting with the DB to get some data to display in the UI and this way the data is unnecessarily fetched twice.