Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Loading image issue

    Hi,

    It's quite strange that every time when i click on the view image button, the image doesn't show up for the first click, but the image will be displayed when the second time the button is clicked.

    on the server side, the first button click invokes the servlet and get image byte array fed back to the client:
    Code:
    04 Jul 09:02:43 INFO  r.servlet.ImageServlet..essRequest:108 - get image from /home/images/07030/11_0/0703011_0.png
    04 Jul 09:02:43 INFO  r.servlet.ImageServlet..essRequest:127 - Writing image png byte[] 139851 bytes to OutputStream
    I've tried using GWT Image to obtain the image details first and then load the image into SmartGWT Img, but it has the same issue. Here's the code how i do it:

    Code:
    public class ImageViewWindow extends Window {
    ......
    ......
                     Image i = new Image("/ImageServlet?connote=" + connoteNumber + "&carrier=" + parentCarrier + "&pageno" + pageNumber + "&type=" + imageType);
    		
    		
    		Img image = new Img("/ImageServlet?connote=" + connoteNumber + "&carrier=" + parentCarrier + "&pageno" + pageNumber + "&type=" + imageType);
    
    		image.setWidth(i.getWidth());
    		image.setHeight(i.getHeight());
    
    
    		final HLayout imgContainer = new HLayout();
    		imgContainer.addMember(image);
    		
    		final HLayout layoutImage = new HLayout();
    		layoutImage.setBackgroundColor("#000");
    		layoutImage.addMember(imgContainer);
    		layoutImage.setOverflow(Overflow.AUTO);
    		layoutImage.setPadding(5);
    
    		this.addItem(layoutImage);
    }
    There's a button in another class, when the button is clicked, this Window will .show(), and load up the image. But now i always have to click on the button, close the window, and click the button again to see the image.

    i've also tried only using a GWT Image to display the image, the same.

    Could you help me with it? Thanks!
    Last edited by liudi; 3 Jul 2011, 17:16.

    #2
    Is GWT returning correct sizes? Since this is a dynamic image, it may not do so until the image is loaded, so you will need to register for the load event and find out the size then.

    Comment


      #3
      Originally posted by Isomorphic
      Is GWT returning correct sizes? Since this is a dynamic image, it may not do so until the image is loaded, so you will need to register for the load event and find out the size then.
      thanks Isomophic. Yes the GWT Image can obtain the correct dimensions of the image even the image doesn't display. The issue i m suspecting is that the HTML <Img> is not placed to the Window component (<div> in HTML?). The image is actually loaded (because server logs display so, and client side can print out image size) and cached, when the second time the button is clicked, no server action is taken, but the image just shows up.

      any clue about this issue?

      Comment


        #4
        No, that doesn't make sense, but you can eliminate the possibility easily by using the Watch tab to see whether the component is there, and Firebug to inspect the HTML if you want to be really sure.

        Comment


          #5
          Hi Iso, i think you are right, the image is not loaded at the first click, i got an error message on the Dev Console Results tab in the logging:

          drawing:isc_HLayout_3:negative or zero area: height: 0, width: 760, refusing to draw
          Class.getStackTrace(_1=>undef, _2=>undef, _3=>undef, _4=>undef)
          Canvas.readyToDraw()
          Canvas.draw(_1=>undef)
          anonymous()
          Layout.layoutChildren(_1=>"initial draw", _2=>undef, _3=>undef)
          Layout.drawChildren()
          ** recursed on Canvas.draw


          Is there a way to prevent from happening? like a CallBack? Thanks!

          Comment


            #6
            If you're providing the right size, this won't happen. Again, wait for GWT Image to load before getting the size and creating these components.

            Comment


              #7
              Yes, i got the idea and found that the image size was not initially correctly obtained.

              could u give me a bit hint about how to 'wait GWT Image to load'? thanks!

              i m thinking of Image.addLoadHandler, is it the right way?

              Comment

              Working...
              X