0

From this post I learned that my page which contains a StreamedContend has to be related to an ApplicationScoped bean, but its has the consequence that if I modify some data (saved in DB) in an other page, the image build with the StreamedContent will not take these modifications into account

Bean

@ManagedBean
@ApplicationScoped
public class ImgBean{
    @EJB
    private EJUser ejuser;

    @PostConstuct
    private void init(){
        // init some lists and objects from DB
    }

    public StreamedContent getChart(){
        //build and return 
    }
}

xhtml

<p:graphicImage id="chart" value="#{imgBean.chart}" >
</p:graphicImage>

My problem is, how to refresh the data inside this Bean, but not everytime it get the chart, because I can stay on this page and refresh the chart a lot of times, but more like when i open the page ?

azro
  • 35,213
  • 7
  • 25
  • 55

2 Answers2

0

Maybe you could try to use @ViewScoped instead.

Annother option would be to add a method that updates the underying data and may be triggerd by a commandButton.

Kimses
  • 462
  • 3
  • 13
0

The metadata can achieve this purpose, onload method here will be called each time the page is open

<f:metadata>
    <f:viewAction action="#{bean.onload}" />
</f:metadata>

and

@ManagedBean
@ApplicationScoped
public class ImgBean{
    @EJB
    private EJUser ejuser;

    @PostConstuct
    private void init(){
        // init some lists and objects from DB
    }

    private void onload(){
        init();        
    }

    public StreamedContent getChart(){
        //build and return 
    }
}
azro
  • 35,213
  • 7
  • 25
  • 55