0

I am new in JSF. I am using Primefaces, I want to create a dynamic graphic with Primefaces. I am passing a parameter through the URL in the context. In the XHTML, I have this code

<p:graphicImage id="linear" value="#{imageController.chart}"> 
    <f:event type="preRenderView" listener="#{imageController.loadChart}" />
</p:graphicImage>

In the bean I have put the code to read the web string parameters in the constructor, loadChart and @PostConstruct method, always with the same result:

private StreamedContent chart;
private Integer id = 0;

public ImageController () {
    System.out.println("ImageController constructor");
    createImgModel();
}

private void createImgModel() {
    //Chart
    try {
        //Get the Id
        System.out.println("ImageController.createModel");
        Map<String, String> requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        if(requestMap.containsKey("id")){
            id = Integer.parseInt(requestMap.get("id"));
        }
        System.out.println("ImageController.id: " + id);
    ...
}

The first time this method is called, I receive the Id param correctly, but the second I receive 0. I have checked both are different threads.

The problem is that I cannot store the id because it is deleted from the first time through the second. I need to receive the id in the second because de valid getChart call is the second one.

Kind regards

Masudul
  • 21,543
  • 5
  • 40
  • 55

0 Answers0