You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by bryan0101 <bt...@gmail.com> on 2008/10/20 12:34:34 UTC

Ajax refresh custom WebComponent fail (an external image by Igor Vaynberg)







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)

&nbsp;

The StaticImage part works great. 

Minor difference:&nbsp; 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

{

&nbsp;&nbsp; private static final long serialVersionUID =
-7600332611457262341L;


&nbsp;&nbsp; public StaticImage(String id, IModel model)

&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(id, model);

&nbsp;&nbsp; }


&nbsp; 

&nbsp;&nbsp; public void resetDefaultModelObject (String url)

&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; setDefaultModelObject(new Model(url));

&nbsp;&nbsp; }


&nbsp;&nbsp; protected void onComponentTag(ComponentTag tag)

&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; checkComponentTag(tag, "img");

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.onComponentTag(tag);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String url =
getDefaultModelObjectAsString();

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; url = url + ((url.indexOf("?")
&gt;= 0) ? "&amp;" : "?");

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


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tag.put("src", url);


&nbsp;&nbsp; }

}



The code to create the StaticImage


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ...

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

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mainImg.setOutputMarkupId(true);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mainImgDiv = new
WebMarkupContainer("mainImgDiv");

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
mainImgDiv.setOutputMarkupId(true);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mainImgUploadLink = new
Link("mainImgUpload")

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void
onClick()

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; setResponsePage(new PopupPage(CurrentPanel.this));

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
mainImgUploadLink.setOutputMarkupId(true);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mainImgUploadLink.add(mainImg);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mainImgDiv.add(mainImgUploadLink);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; panelForm.add(mainImgDiv);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ...



The code to refresh



public void onPopupClose (AjaxRequestTarget target)

&nbsp;&nbsp;&nbsp; {

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (mainImgFile != null)

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
mainImg.resetDefaultModelObject(newImg);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
target.addComponent(newImgComp);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
target.addComponent(mainImgUploadLink);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
target.addComponent(mainImgDiv);

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; }


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.