7 Replies Latest reply on Aug 8, 2008 4:33 PM by rapowder

    s:graphicImage sometimes shows the wrong picture

    rapowder

      Hi,


      I'm using Seam 1.2.1.GA and I'm having a problem with the <s:graphicImage> tag. I developed an application, which is used to edit a customers'database. When loading a person's profile, its picture is shown. Quite randomly it happens that the page displays the wrong picture. Just reloading the page with F5 fixes the problem and the correct image is shown, but the bug is very annoying and I didn't yet find a systematic way to reproduce it.


      I saw the same issue in the old seam forum at this link.
      Apparently it has been fixed on CVS, but I don't know which files were modified and which version I should take.


      Can anyone help? Thanx a lot.
      Andrea

        • 1. Re: s:graphicImage sometimes shows the wrong picture
          rapowder

          I digged a bit more in the seam code and added some debug. Actually, the reasons of some implementation choices are not very clear to me.


          <s:graphicImage> manages the pictures using a Session scoped component
          (org.jboss.seam.ui.graphicImage.dynamicImageStore). This component contains a
          HashMap<String, ImageWrapper> that is supposed to store the opened images.
          The key is the image path, the value is an ImageWrapper.


          The filename can be specified as a parameter in the s:graphicImage tag:
          <s:graphicImage fileName="..."/>.


          If no filename is specified, it is automatically generated by a method in
          DynamicImageStore:



          public String put(ImageWrapper image, String key) {
            if (key == null) {
              key = "org.jboss.seam.ui.DynamicImageStore." + index;
              index++;
            }
            ... 
          }



          A strange implementation of seam is that, in order to show an image, instead of
          just being retrieved by the map.get() method, it is retrieved using the
          map.remove() method in DynamicImageResource:


          ImageWrapper image = DynamicImageStore.instance().remove(pathInfo);



          This makes the use of a session scoped map useless (since the map is always
          empty), because pictures are put and removed in the same request. A consequence
          is that the image cannot be retrieved using the generated url if the path is
          typed as url, and that in some cases another image (probably cached by the
          browser) is used.


          Maybe I am wrong, can someone confirm what I think?

          • 2. Re: s:graphicImage sometimes shows the wrong picture
            pmuir

            Yes, this is a problem.


            Fancy fixing this? Submit a patch in JIRA.

            • 3. Re: s:graphicImage sometimes shows the wrong picture
              rapowder

              In my code i fixed the problem by specify an image filename in my jsf in order not to have a dynamically assigned url to my image. e.g:


              <s:graphicImage value="#{bean.image.data}" fileName="#{bean.image.filename}"/>



              And by patching the code in org.jboss.seam.ui.graphicImage.DynamicImageResource, by replacing the line:


              ImageWrapper image = DynamicImageStore.instance().remove(pathInfo);



              by


              ImageWrapper image = DynamicImageStore.instance().get(pathInfo);



              This avoids to erease picture from the map when the image is displayed.
              I still have to test this a bit more deeply before posting the patch..

              • 4. Re: s:graphicImage sometimes shows the wrong picture
                pmuir

                This is effectively a memory-leak though, and can lead to the session getting too large.

                • 5. Re: s:graphicImage sometimes shows the wrong picture
                  rapowder

                  Yes, I guess you're right, but using a HashMap in the way it is currently used is not a good solution eighter... Do you have any propositions? I didn't yet migrate to Seam 2.0, I wonder if you still have this problem?

                  • 6. Re: s:graphicImage sometimes shows the wrong picture
                    pmuir

                    I don't have any immediate ideas. Still the same problem.

                    • 7. Re: s:graphicImage sometimes shows the wrong picture
                      rapowder

                      ok, I'll keep watching this topic, hoping that this bug is in your plans...
                      thank you for feedback anyway :)