3 Replies Latest reply on Jun 1, 2009 3:48 AM by maitscha

    Dynamic a4j:mediaOutput with Java

    maitscha

      Hi!

      I'd like to create a MediaOutput with Java. Here is my code:

      HtmlDataList imageList = new HtmlDataList();
      imageList.setValueExpression("value", createValueExpression("#{" + beanName + ".dataMap['" + keyString + "'].files}"));
      imageList.setVar("file");
      
      ... // add some items
      
      // thumbnail
      MediaOutput thumbnail = new MediaOutput();
      thumbnail.setId(FacesContext.getCurrentInstance().getViewRoot().createUniqueId());
      thumbnail.setElement("img");
      thumbnail.setCacheable(false);
      thumbnail.setSession(true);
      thumbnail.setRendered(true);
      thumbnail.setValueExpression("value", createValueExpression("#{file.data}"));
      thumbnail.setValueExpression("mimeType", createValueExpression("#{file.contentType}"));
      thumbnail.setCreateContentExpression(createMethodExpression("#{imagePainter.paintThumbnail}"));
      
      // add to imagelist
      imageList.getChildren().add(downloadLink);
      imageList.getChildren().add(spacer);
      imageList.getChildren().add(deleteLink);
      imageList.getChildren().add(thumbnail);
      


      @Name("imagePainter")
      @Scope(ScopeType.STATELESS)
      public class ImagePainter {
      
       public void paintThumbnail(OutputStream out, Object data) throws IOException{
       ... // paints the image to out
       }
      }
      


      The problem is that the MediaOutput is not rendered and the ImagePainter gets not called.

      Any ideas?

      Regards, Christoph.

        • 1. Re: Dynamic a4j:mediaOutput with Java
          ilya_shaikovsky

          any errors in server log?

          • 2. Re: Dynamic a4j:mediaOutput with Java
            maitscha

            No errors, only the following in DEBUG mode:

            07:52:49,213 DEBUG [RendererBase] Start encoding of component trialDataEditorForm:decoAround1_0:j_id91:1:j_id57 with class org.ajax4jsf.component.html.MediaOutput
            07:52:49,213 DEBUG [InternetResourceBuilder] Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1e220c
            07:52:49,213 DEBUG [InternetResourceBuilder] Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1e220c
            07:52:49,230 DEBUG [ResourceBuilderImpl] Build URI for Resource with key [org.ajax4jsf.resource.UserResource/n/s/-1487394660] as : /.../a4j/s/3_2_2.SR1org.ajax4jsf.resource.UserResource/n/s/-1487394660/DATA/eAHsvQdAFMuyMDxkRQVRURQJIiYyS86HDAoiOYlIWDIssCwoCKuioiAgKKAgoJKzZAF....
            07:52:49,244 DEBUG [RendererBase] Finish encoding of component trialDataEditorForm:decoAround1_0:j_id91:1:j_id57 with class org.ajax4jsf.component.html.MediaOutput
            07:52:49,245 DEBUG [RendererBase] Start encoding of component trialDataEditorForm:decoAround1_0:j_id91:2:j_id94 with class org.richfaces.component.html.HtmlSpacer
            07:52:49,245 DEBUG [InternetResourceBuilder] Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1e220c
            07:52:49,245 DEBUG [ResourceBuilderImpl] Build URI for Resource with key [images/spacer.gif] as : /.../a4j/g/3_2_2.SR1images/spacer.gif
            07:52:49,246 DEBUG [RendererBase] Finish encoding of component trialDataEditorForm:decoAround1_0:j_id91:2:j_id94 with class org.richfaces.component.html.HtmlSpacer
            07:52:49,246 DEBUG [RendererBase] Start encoding of component trialDataEditorForm:decoAround1_0:j_id91:2:j_id56 with class org.ajax4jsf.component.html.HtmlAjaxCommandLink
            ...
            


            • 3. Re: Dynamic a4j:mediaOutput with Java
              maitscha

              I have found the answer. The value property must not be too large, so I used a Long for it and now it works.