GraphicImage with StreamedContent doen't work!

UI Components for JSF
Post Reply
n3tmaster
Posts: 14
Joined: 29 Nov 2013, 16:35

22 May 2015, 18:27

Hi guys,
I have a big problem with GraphicImage and StreamedContents using PrimeFaces 5.1

My situation is the following:

I have a PNG raster stored in a PostgreSQL DB (version 9.4 with PostGIS 2.1 and GDAL 1.11); I create a bean method to perform a query to DB in order to get the stored image and show it on my UI page.

My bean:

Code: Select all

@ManagedBean(name="mapUrbanBean")
@SessionScoped

public class MapBean implements Serializable{
private StreamedContent image1;

//....

//bean getter
public StreamedContent getImage1() {
        FacesContext context = FacesContext.getCurrentInstance();
        
        if(context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE){
            return new DefaultStreamedContent();
        }else{
            return image1;
        }
        
       
    }

}

//...


/**
* Note: dsm is an istance of my Class for DB connection management
*/
public void queryImage(){
//...
         InputStream imgReaded;


         dsm.setPreparedStatementRef("Select ST_AsPNG(ST_ColorMap(rast,1,colormap)) from  my_raster_table order by data desc");  //this query uses PostGIS functions in order to extract the PNG image
        
        dsm.runPreparedQuery();
         
        if(dsm.next()){
         
            imgReaded = dsm.getBStream(1); //getBStream retrieves the    BinaryStream of the image

             image1 = new DefaultStreamedContent(imgReaded , "image/png"); //save the image in the StreamedContent
        }

}


//....
and this is my JSF code

Code: Select all

 <p:graphicImage id="rasterout" value="#{mapUrbanBean.image1}" binding="#{rasterout}" cache="false"/>
 <p:commandButton   title="showImg" 
                                                        update=":#{rasterout.clientId} "
                                                        action="#{mapUrbanBean.queryImage}" 
                                                        
                                                        />


When the page being loaded , I got a "500 Server Error".
In the tomcat log file I was able to see that getImage1 getter function is called during the page load phase...
Moreover the method that performs the Postgresql query works fine.


My project specs: PrimeFaces 5.1, Tomcat 6, JDK 1.7, JDBC 41 for Postgresql 9.4, Mojarra 2.2.2 (I'm using NetBeans with Maven)

Any idea? Thank you in advance and sorry for my bad english

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests