2 Replies Latest reply on Oct 6, 2008 7:03 AM by Ilya Shaikovsky

    aj4:mediaOutput doesn't rerender after ajax request

    Markus Kühle Newbie

      In my scenario the aj4:mediaOutput component is rendering an captcha image and it should be possible to get another one if user can't read current one. The createContent Attribute calls a method which creates an image with a text string on it. The text string is stored in an attribute on captcha backing bean. If the ajax button is pressed this string will be replaced by another one on captcha backing bean and the medioOutput should rerender the image again after the ajax return, but it doesn't rerender the image.

      xhtml:

      <h:form>
      <a4j:region id="testRegion" ajaxRendered="true">
       <a4j:mediaOutput element="img" cacheable="false" standby="creating image" value="test" createContent="#{CaptchaBB.paintCaptcha}" mimeType="image/jpeg" />
       <a4j:commandButton id="changeCaptchaBtn" action="#{CaptchaBB.replaceCaptcha}" value="#{msg.registerUser_captchaReplace}" reRender="testRegion" />
      </a4j:region>
      </h:form>


      Backing Bean:
      public class CaptchaBB {
      
       private String captchaString = "captchaString";
      
       public void paintCaptcha(OutputStream out, Object param) throws IOException{
       CaptchaRenderer captchaRenderer = new CaptchaRenderer();
      
       BufferedImage myImg = captchaRenderer.createCaptchaImage(captchaString);
       ImageIO.write(myImg,"jpeg",out);
       }
      
       public String replaceCaptcha(){
       captchaString = "new";
       return null;
      
       }
      


      The string is replaced correctly on server side but the method, defined on createContent, will not called again. This backing bean is placed in session scope for developing and if i load the whole page again the new string will be rendered. So the only problem is that the a4j:mediaComponent will not call the BackingBean method defined in createContent attribute.

      Does anyone has an idea?

      Markus