0

Environment:

  • Primefaces 10
  • JSF 2.3

I am trying to load a profile image on a template jsf page, the first load works fine an the image appear but when I move to another page image dissapears. The image is loaded on session scoped bean when session is created. I also tried to upload with bytes array but same result.

Any idea what the problem is?

index.xhtml

<p:graphicImage id="img" value="#{sessionBean.imgProfile}"/>

SessionBean.java

@Named
@SessionScoped
public class SessionBean implements Serializable {
    ...
    private StreamedContent imgProfile;

    //-------------------------------------------------------------------------
    // Methods
    //-------------------------------------------------------------------------
    @PostConstruct
    public void init() {
        ...

        Document d = getUsuari().getDocImatge();
        imgProfile = DefaultStreamedContent.builder()
                .stream(d::getInputStream)
                .contentType(d.getTipus())
                .name(d.getFileName())
                .build();
        ...
    }
    
    public StreamedContent getImgProfile() {
        return imgProfile;
    }
    ...
}
Joe
  • 7,749
  • 19
  • 60
  • 110
  • Seems like you bean is not really session scoped, maybe there's an issue with the import. Can you check if it's the right one? I cannot see your import but this is a possible problem. – Simone Lungarella Aug 20 '21 at 20:57

1 Answers1

1

You currently need to create a new DefaultStreamedContent each time in your getter. We will fix this for 11.0: https://github.com/primefaces/primefaces/issues/7730

tandraschko
  • 2,291
  • 13
  • 13