public StreamedContent getPicture ( ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; if ( context . getCurrentPhaseId ( ) == PhaseId . RENDER_RESPONSE ) { // So, we're rendering the HTML. Return a stub StreamedContent so // that it will generate right URL. LOG . fine ( " return empty picture" ) ; return new DefaultStreamedContent ( ) ; } else { // So, browser is requesting the image. Return a real // StreamedContent with the image bytes. String pictureId = context . getExternalContext ( ) . getRequestParameterMap ( ) . get ( "pictureViewId" ) ; PictureData picData = ( PictureData ) FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . getSessionMap ( ) . get ( pictureId ) ; FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . getSessionMap ( ) . remove ( pictureId ) ; LOG . fine ( " return real picture and remove session" ) ; return new DefaultStreamedContent ( new ByteArrayInputStream ( picData . getData ( ) ) ) ; } }
Return picture to web front end .