GWT Button eventlistener designer
For example I took html from a designer which is given below. How can i add click event which shows a开发者_运维百科lert from GWT?
<table align="center">
<tr>
<td id="nameFieldContainer"><input type="button" name="x" id="x" value="OK" /></td>
</tr>
</table>
The button:
final Button button = new Button("OK");
I dont allow to add button dynamically from GWT by
RootPanel.get("sendButtonContainer").add(button);
I am searching the syntax something like:
RootPanel.get("sendButtonContainer").getWidget(0).addEventListener()
Jquery can search the button object from nameFieldContainer
and
dynamically add click event listener but is it possible in GWT??
You're looking for ClickHandler. Listeners were deprecated some time ago.
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// do something...
}
}
edit: I may have misunderstood your question. If you no longer have a reference to the button you could do
// code removed because it's really not the best way to solve this problem, and led to confusion...
But you'll have to be very sure that the element inherits from HasClickHandlers
-- and you should really just keep a reference to the button, it's much cleaner that way.
精彩评论