jadrake75
17 Jul 2009, 9:17 AM
I wanted to use image bundles to represent the image in a Grid using GXT 2.0. Prior to support for widgets, I used a simple <span ..><img src="..."/></span> block as HTML output. Since there is no IconSupported class that represents an image component I created one called "Image". I used Button as the basis for the design. I am having a problem though... the img and span tags do not seem to get added to the DOM. I tried debugging this and I do see the proper progression of the component created (the <span> tag in the onRender( ) followed by the call of the setIcon in the afterRender which correctly inserts the <img>) but the <span> element does not appear to become attached to the DOM. Using a DOM inspector I was unable to locate it (I am setting the ID specifically). Any hlep would be a great assistance!
package org.javad.client.stamp.components;
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.BoxComponent;
import com.extjs.gxt.ui.client.widget.IconSupport;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
public class Image extends BoxComponent implements IconSupport {
private AbstractImagePrototype icon = null;
private El wrapperEl = null;
@Override
public AbstractImagePrototype getIcon() {
return icon;
}
@Override
public void setIcon(AbstractImagePrototype icon) {
if (rendered) {
if (wrapperEl.selectNode("img") != null) {
wrapperEl.selectNode("img").remove();
}
if (icon != null) {
Element e = (Element) icon.createElement().cast();
wrapperEl.insertFirst(e);
El.fly(e).makePositionable(true);
El.fly(e).alignTo(wrapperEl.dom, "tl-tl", null);
}
}
this.icon = icon;
}
@Override
public void setIconStyle(String icon) {
setIcon(IconHelper.create(icon));
}
@Override
protected void afterRender() {
super.afterRender();
setIcon(icon);
}
@Override
protected void onRender(Element target, int index) {
Template template = new Template("<span id='{0}'></span>");
setElement( template.create(getId()), target, index);
super.onRender(target, index);
wrapperEl = el();
}
}
package org.javad.client.stamp.components;
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.BoxComponent;
import com.extjs.gxt.ui.client.widget.IconSupport;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
public class Image extends BoxComponent implements IconSupport {
private AbstractImagePrototype icon = null;
private El wrapperEl = null;
@Override
public AbstractImagePrototype getIcon() {
return icon;
}
@Override
public void setIcon(AbstractImagePrototype icon) {
if (rendered) {
if (wrapperEl.selectNode("img") != null) {
wrapperEl.selectNode("img").remove();
}
if (icon != null) {
Element e = (Element) icon.createElement().cast();
wrapperEl.insertFirst(e);
El.fly(e).makePositionable(true);
El.fly(e).alignTo(wrapperEl.dom, "tl-tl", null);
}
}
this.icon = icon;
}
@Override
public void setIconStyle(String icon) {
setIcon(IconHelper.create(icon));
}
@Override
protected void afterRender() {
super.afterRender();
setIcon(icon);
}
@Override
protected void onRender(Element target, int index) {
Template template = new Template("<span id='{0}'></span>");
setElement( template.create(getId()), target, index);
super.onRender(target, index);
wrapperEl = el();
}
}