Jaroslav, this code does more or less what you want.
package br.com.andre.gwt.samples.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Samples implements EntryPoint {
@Override
public void onModuleLoad() {
MyButton button = new MyButton("<h1> this is a nice html</h1>");
Element htmlEl = button.getElement();
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Houston We have lift-off!");
}
});
RootPanel myRoot = RootPanel.get("placeholder");
if (myRoot != null) {
Element myRootParent = myRoot.getElement().getParentElement();
if (myRootParent != null) {
myRootParent.insertAfter(htmlEl, myRoot.getElement());
myRootParent.removeChild(myRoot.getElement());
}
}
button.attach();
}
public class MyButton extends Button {
public MyButton(String html) {
super(html);
}
public void attach() {
this.onAttach();
RootPanel.detachOnWindowClose(this);
}
}
}
I used the Idea which was implemented in the method wrap of the Button
class
Button.wrap(element);
As far as i read the docs, the onAttach() allows the element to start
receiving events from the browser.
Hope it helps,
On 19 jun, 13:27, Jaroslav Záruba <
jaroslav.zar...@gmail.com> wrote:
> I'm creating widget that is supposed to check whether there's an <a/>
> element with known id in the page. If the element is found my widget reads
> the href attribute and loads stuff from that URL, then displays
> the (processed) content exactly where user indicated by that <a/>. (Placing
> my widget into <a/> has several obvious side-effect I don't like.)
> If the element is not found then the link works as usually.
>
> Is the fact that this is impossible to do a mere result of 'no one thought
> anyone would need that'? :)
>
> 2010/6/19 Jaroslav Záruba <
jaroslav.zar...@gmail.com>
>
>
>
> > 2010/6/19 André Moraes <
andr...@gmail.com>