5 Replies Latest reply on Sep 13, 2007 12:53 PM by ilya_shaikovsky

    Unable to refresh an image using a4j:support

    jsfguru

      Environment:

      Platform: Windows XP Professional SP2
      JDK: Sun JVM 1.5.0 Patch 8
      Application server: JBoss 4.0.5GA
      JSF: Apache MyFaces 1.1.4
      Facelets: Sun RI 1.1.11
      AJAX4JSF: 1.1.0
      Browser: FireFox 2.0, IE 7.0

      We have a requirement on a web page where a trend graph is loaded on the left-hand side and a number of parameters on the right-hand side. The idea is that if the user checks one of the parameters on the right-hand side, the trend graph should refresh and show the trends for that parameter.

      Code is as follows:

      <h:graphicImage alt="Trend" height="300" id="imgTrend" title="Trend" value="/TrendChartGenerator" width="600" />
      
      <div>
       <h:selectBooleanCheckbox id="chk11">
       <a:support event="onchange" reRender="imgTrend" actionListener ="#{sampleBean.updateGraph}" ajaxSingle="true" limitToList="true">
       <a:actionparam name="unitId" value="11" />
       </a:support>
       </h:selectBooleanCheckbox>
       North
      </div>
      


      The problem I am facing is that on checking the box, the image does not refresh. If I try to refresh say a text box, that works fine.

      I am guessing this is because the browser is caching the image. My web page has a Cache-Control directive at the top, which is set to no-cache.

      Is there a way to make this work?

        • 1. Re: Unable to refresh an image using a4j:support

          Probably, you can avoid this caching by changing the value attribute.
          Also, you can try to use a:mediaOutput that has cachable attribute.

          • 2. Re: Unable to refresh an image using a4j:support
            jsfguru

            Thanks for the pointers.

            I have just now finished trying the mediaOutput approach. That didn't work either.

            I have found one example posted by another user which seems to indicate that my original code should work (at least it worked for the other user). Let me try copying that code and see.

            • 3. Re: Unable to refresh an image using a4j:support
              jsfguru

              Solved it. I had to change

              <h:graphicImage value="/TrendChartGenerator" />
              


              to

              <h:graphicImage value="#{sampleBean.chartURL}" />
              


              and here is the getChartURL method:

              public String getChartURL()
              {
               return "/TrendChartGenerator?cacheid=" + (Math.random() * 1000000);
              }
              


              Basically, as suggested by Sergey, I had to make the image URL dynamic, fooling the browser into thinking that the image source had changed and hence had to be refreshed.

              • 4. a4j:include
                ggeorgi

                hi
                I am trying to include a jsp into another one using a4j.
                for example. we have first.jsp, whish contains only one tag:
                <h:output value="hallo">
                the second one should have a button and after a click the first.jsp should be shown.
                how could I get this

                the following code doesn't success:
                <a4j:commandButton reRender="adJsp" value="add"/>
                <a4j:outputPanel id="adJsp">
                <a4j:include viewId="second.jsp"></a4j:include>
                </a4j:outputPanel>
                a button is shown and the jsp is shown too. If clicked, the button doesn't change anything.

                • 5. Re: Unable to refresh an image using a4j:support
                  ilya_shaikovsky

                  navigation inside include works only for the components inside include