2010-12-12 23 views
0

Je souhaite ajouter un gestionnaire de clic à une ancre définie dans un panneau gwt html sans succès. J'utilise la méthode suivanteGWT ajoute un gestionnaire d'événement à l'élément dom

panel_1 = new HTMLPanel("<div class='BackHeader'>Selected Attribute:Select an Attribute to edit(<a Id='DeleteCategory'>Delete this Attribute</a>)</div>"); 
    flexTable.setWidget(3, 0, panel_1); 
Element DeleteCategory=panel_1.getElementById("DeleteCategory"); 
    Anchor C= Anchor.wrap(DeleteCategory); 

Mais je reçois les erreurs suivantes:

Exception while loading module com.BiddingSystem.client.BiddingSystem. See Development Mode for details. 
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.AssertionError at com.google.gwt.user.client.ui.Anchor.wrap(Anchor.java:55) at com.BiddingSystem.client.View.ProductTaxonomyView.(ProductTaxonomyView.java:174) at com.BiddingSystem.client.BiddingSystem.onModuleLoad(BiddingSystem.java:63) ... 9 more 

Répondre

1
Anchor a = new Anchor("hi"); 
a.addClickhandler(new ClickHandler() { 
    @Override 
    public void onClick(ClickEvent event) { 
      Window.alert("hi"); 
    } 

}); 
0

Je vous suggère de simplement utiliser le UIBinder ... jetez un oeil à this tutorial. Pour l'ancre, vous utiliserez l'élément <g:Anchor>.

0

Votre HTMLPanel n'est pas joint au document.

Vous pouvez uniquement transmettre des éléments attachés à la méthode wrap().