Reputation: 1
I’m having some trouble getting the primefaces dyanmic graphic image to display for a certain scenario where I’m trying to display an image on a facelet page (retrieved from a database) and the page is invoked by a URL (not h:commandLink). It works on other pages with requests processed through h:commandButton. However all the data but the image appears for the following scenario...
fundraiseView.xml (facelet page) html ... p:graphicImage value="#{fundraisePage.picture}"/ ... /html
FundraisePage (request scoped backing bean with request param)
@ManagedBean
@RequestScoped
public class FundraisePage extends BackingBean {
@EJB DataSBLocal dataSB;
StreamedContent picture;
@ManagedProperty(value="#{param.id}")
private int id;
@PostConstruct
public void init() {
this.fundRaiseEO = dataSB.getFundRaiseIndividual(id);
InputStream inputStream = new ByteArrayInputStream(this.fundRaiseEO.getPicture());
this.setPicture(new DefaultStreamedContent(inputStream, "image/jpeg"));
}
When I invoke the page via http://...../faces/fundraiseView.xml?id=1 the page returns displaying all the data for id 1 but without displaying the picture. I’m sure it has to do with how I’m calling the page (since I have it working else where) however I need it to be a request initiated outside a JSF wrapped tag.
Any insight or suggestions very much appreciated.
Thanks, Johnathan
Upvotes: 0
Views: 3471
Reputation: 11
Found the answer in another thread.
Loading a set of images with primefaces
I needed to use tag f:parm name="id" value="#{fundraisePage.id}" within the p:graphicImage tag so it accepts the id as a lookup param. As well change the value on image tag to this method in property...
public StreamedContent getImage () {
FundRaise fundRaiseEO = new FundRaise();
fundRaiseEO = dataSB.getFundRaiseIndividual(id);
return new DefaultStreamedContent(new ByteArrayInputStream(fundRaiseEO.getPicture()), "image/jpeg"); \\ or whatever your image mime type.
}
Upvotes: 1