0

I have a bean

@ManagedBean
@ViewScoped
public class ProfileBean implements Serializable{
...

private StreamedContent photo2;

public ProfileBean() {

    InputStream iStream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/resources/images/somePhoto.png");

    photo2 = new DefaultStreamedContent(iStream, "image/png");

    } 
public StreamedContent getPhoto2() {
    return photo2;
}

public void setPhoto2(StreamedContent photo2) {
    this.photo2 = photo2;
}

}

and graphicImage

<p:graphicImage value="#{profileBean.photo2}" library="images" width="110" height="150" id="photo" />

the picture not appears/ I tried, like advised here

but both requests are RENDER_RESPONSE...

may be there is alternative way, maybe without primefaces?

Community
  • 1
  • 1
evp
  • 1
  • The duplicate explains your technical question. However, your code is quite strange as you're basically returning a public web resource from external context. Not sure if this is test code, but you can instead of that also just use ``. – BalusC Feb 17 '16 at 15:12
  • this is just example. I want in future use byte[] as image resource. I want to understand how it works, if i use StreamedContent. in the next step picture must come through the post-responce from another site – evp Feb 17 '16 at 15:24
  • the example you showed did not work, I do not understand why, but the function really works twice, but both times context.getCurrentPhaseId() is PhaseId.RENDER_RESPONSE – evp Feb 17 '16 at 15:35
  • It works for me. Apparently you did it differently from the answer. Perhaps it's still view scoped, or you still created it as bean property (as shown in your current question), who knows. The answer at least explains precisely why your approach won't work. – BalusC Feb 17 '16 at 15:39

0 Answers0