价格-如何刷新< p:graphicImage>从单击< p:commandButton>? [英] PRIMEFACES - How to refresh a <p:graphicImage> from clicking a <p:commandButton>?

查看:101
本文介绍了价格-如何刷新< p:graphicImage>从单击< p:commandButton>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm considering this showcase: http://www.primefaces.org/showcase/ui/dynamicImage.jsf in particular the sub-case "GraphicText on-the-fly".

我的问题是通过添加来实现此子案例的扩展版本.按下按钮后,我需要图像进行动态更改.

My problem is implementing an extended version of this sub case with the addition of a . When the button is pressed i need that the image change dinamically.

在DynamicImageController类中,我重写了与graphicImage关联的吸气剂:

In the DynamicImageController class I re-writed the getter associeted with the graphicImage:

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;
 }

我有这个按钮:

<p:commandButton id="refreshImageButton" value="Refresh image random">
                <p:ajax update=":idForm" />
             </p:commandButton>

和图片:

<p:graphicImage value="#{dynamicImageController.graphicText}" />

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

idForm is the form id of the form containing my graphicImage and my commandButton

我的问题是:

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

Why if I press the F5 button on the keyboard the image change random consistent with the desired behavior in the getGraphicText method ? And why when I press the button the image doesn't change?

谢谢.

ps.我真正的问题是jcaptcha在primefaces中的集成,我的集成几乎终止了,我只错过了captcha图像的刷新按钮

ps. my real problem is the integration of jcaptcha in primefaces, my integration is almost termineted, i miss only the refresh button for the captcha image

推荐答案

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

By default the graphicImage caches the image.
Set the cache attribute to false on your p:graphicImage
Something like this:
<p:graphicImage value="#{dynamicImageController.graphicText}" cache="false" />

这篇关于价格-如何刷新&lt; p:graphicImage&gt;从单击&lt; p:commandButton&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆