PRIMEFACES - 如何通过单击<p:commandButton>刷新<p:graphicImage>?

use*_*345 7 ajax captcha primefaces page-refresh jsf-2

我正在考虑这个展示:http://www.primefaces.org/showcase/ui/dynamicImage.jsf,特别是子版"GraphicText on the the-fly".

我的问题是实现这个子案例的扩展版本,增加了一个.当按下按钮时,我需要图像改变.

在DynamicImageController类中,我重新编写了与graphicImage相关联的getter:

public StreamedContent getGraphicText(){
     double random = Math.random();// a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
     if(random>0.5){
         BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);  
         Graphics2D g2 = bufferedImg.createGraphics();  
         g2.drawString("This is a text", 0, 10);  
         ByteArrayOutputStream os = new ByteArrayOutputStream();  
         try {
            ImageIO.write(bufferedImg, "png", os);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
         graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");
     } else {
         BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);  
         Graphics2D g2 = bufferedImg.createGraphics();  
         g2.drawString("This is another text", 0, 10);  
         ByteArrayOutputStream os = new ByteArrayOutputStream();  
         try {
            ImageIO.write(bufferedImg, "png", os);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
         graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");
     }
     return graphicText;
 }
Run Code Online (Sandbox Code Playgroud)

我有这个按钮:

<p:commandButton id="refreshImageButton" value="Refresh image random">
                <p:ajax update=":idForm" />
             </p:commandButton>
Run Code Online (Sandbox Code Playgroud)

和图像:

<p:graphicImage value="#{dynamicImageController.graphicText}" />
Run Code Online (Sandbox Code Playgroud)

idForm是包含我的graphicImage和commandButton的表单的表单id

我的问题是:

为什么我按下键盘上的F5按钮,图像随机变化与getGraphicText方法中的所需行为一致?为什么当我按下按钮时图像不会改变?

谢谢.

PS.我真正的问题是jcaptcha在primefaces中的集成,我的集成几乎是有限的,我只想念验证码图像的刷新按钮

S1L*_*IOR 11

默认情况下,graphicImage缓存图像.
将cache属性设置为 像这样false的p:graphicImage
东西:
<p:graphicImage value="#{dynamicImageController.graphicText}" cache="false" />


use*_*345 2

好的更新:问题是 primefaces 的错误,我在这里讨论了问题:

http://forum.primefaces.org/viewtopic.php?f=3&t=35637&p=113830#p113830