You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project when I render an image with a p:graphicImage I use this method:
public StreamedContent getStreamGeneric(MyPicture myPic) throws Exception { FacesContext context = FacesContext.getCurrentInstance(); try{ if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL. return new DefaultStreamedContent(); } else { // So, browser is requesting the image. Return a real StreamedContent with the image bytes. return MyUtils.getStream(myPic); } }catch (Exception e) { return new DefaultStreamedContent(); } }
Using the view scope the render of the picture doesn't works.
I wrote this workaround in com.github.jneat.jsf.ViewScope :
` @OverRide
public Object get(String name, ObjectFactory objectFactory) {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
if(viewRoot!=null){
//this is true: FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE
`
In this way it works, it does not go into null pointer when FacesContext.getCurrentInstance().getViewRoot() is null (after the render response phase)
Are there any contraindications in my fix? If it is a good fix, you could implement it in the project?
Thanks.
The text was updated successfully, but these errors were encountered:
Hello. Probably you should submit it as a pull request because I can not see from your comment what changes you've made. And thus I can not review it properly.
Hi, I'm tryng your spring custom view scope.
In my project when I render an image with a p:graphicImage I use this method:
public StreamedContent getStreamGeneric(MyPicture myPic) throws Exception { FacesContext context = FacesContext.getCurrentInstance(); try{ if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL. return new DefaultStreamedContent(); } else { // So, browser is requesting the image. Return a real StreamedContent with the image bytes. return MyUtils.getStream(myPic); } }catch (Exception e) { return new DefaultStreamedContent(); } }
Using the view scope the render of the picture doesn't works.
I wrote this workaround in com.github.jneat.jsf.ViewScope :
` @OverRide
public Object get(String name, ObjectFactory objectFactory) {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
if(viewRoot!=null){
//this is true: FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE
`
In this way it works, it does not go into null pointer when FacesContext.getCurrentInstance().getViewRoot() is null (after the render response phase)
Are there any contraindications in my fix? If it is a good fix, you could implement it in the project?
Thanks.
The text was updated successfully, but these errors were encountered: