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 <[email protected]> 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 <[email protected]>
>
>
>
> > 2010/6/19 André Moraes <[email protected]>
>
> > Jaroslav,
>
> >> Maybe instead of reaplacing you delete than insert again the element?!
>
> > I don't understand. What would be the benefit? :)
> > Let's say the placeholder element was third node within its parent. How can
> > I place my widget in its place?
> > (I do apologize, I'm still new to GWT.)
>
> >> I think that the problem of not getting Clicks is because of the way
> >> GWT handles clicks.
>
> > I believe I would have to call Panel.adopt(widget), judging by
> > GWT-sources... Unfortunately RootPanel does not expose adopt. :(
>
> >> Another approach will be make that placehoder element be an actual GWT
> >> Widget (FlowPanel is simply a DIV) and then you add your widgets to
> >> that panel.
>
> > I only know id of the placeholder element, I'm not creating it, therefore I
> > can't make it a Widget.
> > After a widget is created it should replace that element and the element
> > should go to eternity.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.