I'm trying to refresh a custom components describe in
http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html
http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html 
.
It's an External image wrapped in a link (clickable image)

 

The StaticImage part works great. 

Minor difference:  Instead
of wrapping in ExternalLink,
I just wrap it in Link to opened in a popup, and the popup calls back
the page's function with ajaxrequest. 


WIth the requestTarget, one would
think it should be able to ajax refresh the component. Ive tried
Component.replaceWith(newComponent) by creating a
new StaticImage Component, no luck. I've tried
changing the
Model, the
model and/or URL got changed, but the image refused to refresh no
matter what. 


Next I'm tempted to just try and wrap all this in a Panel and do a
replaceWith and see, but this is heavy and I try not to do that.

If there are other options I'd glad to try out. Thanks


The StaticImage class:


public class StaticImage extends WebComponent

{

   private static final long serialVersionUID =
-7600332611457262341L;


   public StaticImage(String id, IModel model)

   {

       super(id, model);

   }


  

   public void resetDefaultModelObject (String url)

   {

       setDefaultModelObject(new Model(url));

   }


   protected void onComponentTag(ComponentTag tag)

   {

       checkComponentTag(tag, "img");

       super.onComponentTag(tag);

       String url =
getDefaultModelObjectAsString();

        url = url + ((url.indexOf("?")
>= 0) ? "&" : "?");

        url = url + "wicket:antiCache=" +
System.currentTimeMillis();


        tag.put("src", url);


   }

}



The code to create the StaticImage


        ...

        mainImg = new StaticImage
("mainImg",new
Model("http://img519.imageshack.us/test1.gif";));

        mainImg.setOutputMarkupId(true);

        

        mainImgDiv = new
WebMarkupContainer("mainImgDiv");

       
mainImgDiv.setOutputMarkupId(true);

        

        mainImgUploadLink = new
Link("mainImgUpload")

        {

            public void
onClick()

            {

           
    setResponsePage(new PopupPage(CurrentPanel.this));

            }

        };


       
mainImgUploadLink.setOutputMarkupId(true);

        mainImgUploadLink.add(mainImg);

        mainImgDiv.add(mainImgUploadLink);

        panelForm.add(mainImgDiv);

        ...



The code to refresh



public void onPopupClose (AjaxRequestTarget target)

    {

        if (mainImgFile != null)

        {

            String newImg
= "http://img519.imageshack.us/newtest.gif";;

           
mainImg.resetDefaultModelObject(newImg);

            

           
target.addComponent(newImgComp);

           
target.addComponent(mainImgUploadLink);

           
target.addComponent(mainImgDiv);

        }

    }


Any help would be greatly appreciated. Thanks.







-- 
View this message in context: 
http://www.nabble.com/Ajax-refresh-custom-WebComponent-fail-%28an-external-image-by-Igor-Vaynberg%29-tp20066916p20066916.html
Sent from the Wicket - User mailing list archive at Nabble.com.

Reply via email to