3 Replies Latest reply on Apr 27, 2009 2:20 PM by james holder

    a4j:mediaOutput not working with c:set and/or Facelets ui:pa

    james holder Newbie

      All,

      I'm trying to use a4j:mediaOutput to display a dynamically generated chart. I have it working when I explicitly define the bean the data is coming from (via createContent), however, when I attempt to generify the source location of hte data I receive the following error:

      Servlet failed with Exception
      javax.faces.FacesException: Error decode resource data
       at org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:618)
       at org.ajax4jsf.resource.ResourceBuilderImpl.getResourceDataForKey(ResourceBuilderImpl.java:360)
       at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:156)
       at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:484)
       Truncated. see log file for complete stacktrace
      java.util.zip.DataFormatException: incorrect data check
       at java.util.zip.Inflater.inflateBytes(Native Method)
       at java.util.zip.Inflater.inflate(Inflater.java:215)
       at java.util.zip.Inflater.inflate(Inflater.java:232)
       at org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:612)
       at org.ajax4jsf.resource.ResourceBuilderImpl.getResourceDataForKey(ResourceBuilderImpl.java:360)
       Truncated. see log file for complete stacktrace
      



      The code I use that works is as follows:
      <a4j:mediaOutput
       id="gantt2"
       element="img"
       cacheable="false"
       session="false"
       createContent="#{sampleBean.outputChart}"
       mimeType="image/png"/>



      When I try and generify this (and the problem shows up), I do the following:

      Parent Page (this is withing a normal Facelets page):



      <ui:include src="components/myData.xhtml">
       <ui:param name="chart" value="#{sampleBean.outputChart}"/>
       </ui:include>
      
      


      Source of "components/myData.xhtml":


      <a4j:mediaOutput
       id="gantt2"
       element="img"
       cacheable="false"
       session="false"
       createContent="#{chart.outputChart}"
       mimeType="image/png"/>
      


      Besides using ui:param (with facelets), this also fails using the same type of setting using c:set, so for instance:

       <c:set var="chart" value="#{sampleBean.outputChart}"/>
      
      



      My premise is that I've got the same type of chart, that I want to call twice, but provide it different data sets. So I create an instance of my chart generating class inside each bean, and then just include the display page in each different template.

      I'm not sure why this isn't working. I've checked the object signatures, and they are different for each bean (ie, when in page 1 using bean1, the #{chart} is the correct object, the same for page2 bean2)

      I'm not sure if I'm missing something or what here.

      using jsf1.2
      richfaces snapshot 3.3.1-20090228.050541-31 (due to bug in 3.3.0 regarding messaging from components w/ no id's)
      facelets 1.1.14

      Thanks for any suggestions




        • 1. Re: a4j:mediaOutput not working with c:set and/or Facelets u
          james holder Newbie

          anyone?

          Looks like issue is being thrown from decrypt() in ResourceBuilderImpl

          Everything works properly when I reference my beans directly, but not when I alias them. :(

          • 2. Re: a4j:mediaOutput not working with c:set and/or Facelets u
            Nick Belaevski Master

            Hello,

            a4j:mediaOutput renders in two stages:

            1. Component itself is rendered, tag (IMG, OBJECT, etc) with proper URI attribute is output to the page.

            2. Browser fetches media content in the separate request: server calls "createContent" that writes media bytes to provided OutputStream

            Looks like you are having problems on stage 2 - server cannot resolve right instance of "chart" thus failing. Solution: pass "chart" (or key part of it - this object should be as small as possible) into "value" attribute and reimplement "createContent" so that it can work in that way.

            Take a look at livedemo example for more.

            • 3. Re: a4j:mediaOutput not working with c:set and/or Facelets u
              james holder Newbie

              Ok, I think I finally have a decent understanding of what is going on here. I saw the notes in the documentation about serializing "large objects", and I think our ideas differ regarding what constitutes a large object. (i didn't consider a 12 propery object to be large until today)

              Sooo, that being said, I'm able to get everything working when I pass in a single string. I have however, lots of data that needs to be utilized to create the image I'm working on.

              So my question is, what are others using to get around this contraint? What I mean by that is, what are others passing into to mediaOutput, that lets them tie back to a given bean property?