Take the 2-minute tour ×

This is my .xhtml

<div id="detailed_div_graph" align="center">
            <p:lineChart id="linear" value="#{ChartBean.linearModel}" legendPosition="e" 
                title="Medical Data" minY="0" maxY="10" style="height:300px"/>

This is my ChartBean code:

public class ChartBean implements Serializable {

private CartesianChartModel linearModel;

public ChartBean() {  

public CartesianChartModel getLinearModel() {  
    return linearModel;  

private void createLinearModel() {  
    linearModel = new CartesianChartModel();  

    LineChartSeries series1 = new LineChartSeries();  

    series1.set(1, 2);  
    series1.set(2, 1);  
    series1.set(3, 3);  
    series1.set(4, 6);  
    series1.set(5, 8);  



What's wrong with my code?

share|improve this question

1 Answer 1

Here you assume that this constructor will be called.

public ChartBean() {  

Jsf has phases and you should take into account them.

If you want your createLinearModel() method to be called at first just after the bean first initialized, you should annotate it with @PostConstruct annotation

private void createLinearModel(){
share|improve this answer

Your Answer


