primefaces 4.0 p:graphicImage firefox bug

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 18:34:07

问题


Here is my problem with firefox using primefaces 4.0 communication version: p:graphicImage I have a list of model, whenever I click 1 item, I would like to get 1 image respectively In xhtml file

<p:fieldset id="modelDiagramView" style="width:100%;height:1280px">
    <p:panel id="panel">
        <p:graphicImage value="#{modelBean.modelImage}" style="width: 100%;" cache="false"/>
    </p:panel>
</p:fieldset>

in java bean, only session scope and application scope are running well

public StreamedContent getModelImage() {
        FacesContext context = FacesContext.getCurrentInstance();

        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            System.out.println("render_response: id=" + modelID);
            // So, we're rendering the HTML. Return a stub StreamedContent so
            // that it will generate right URL.
            // modelImage = new DefaultStreamedContent();
            if (modelID != null)
                getModelImage(modelID);
        } else {
            System.out.println("real reander: id=" + modelID);
            if (modelID != null)
                getModelImage(modelID);
        }
        return modelImage;
    }

In chrome, when I click to item in list, the p:graphicImage will render a new image, however in firefox, only the first item's image will be render, if I want to display the next clicked item, I have to refresh browser(F5). Is it primefaces bug, how can I prevent that problem? Please help me


回答1:


It's just a "bug" that browsers doesn't refresh a image with ajax if the URL will not be changed. Therefore you should add a random number to the resource url as below example.

xhtml

<p:graphicImage value="#{bean.stream}" id="pic" width="200">
   <f:param name="randomNumber" value="#{beanxxx.randomNumber}"/>
</p:graphicImage>

beanxxx

public String getRandomNumber() {
    Random r = new Random();
    int low = 10;
    int high = 100;
    int result = r.nextInt(high-low) + low;

    return Integer.toString(result);
}



来源:https://stackoverflow.com/questions/21498124/primefaces-4-0-pgraphicimage-firefox-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!