Assuming the following *.ui.xml file:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:VerticalPanel>
<g:Label ui:field="Label1"></g:Label>
<g:Label ui:field="Label2"></g:Label>
<g:Label ui:field="Label3"></g:Label>
</g:VerticalPanel>
If I now want to add ClickHandlers to all three Labels like this:
@UiHandler("Label1")
void handleClick(ClickEvent event) {
//do stuff
}
@UiHandler("Label2")
void handleClick(ClickEvent event) {
//do stuff
}
@UiHandler("Label3")
void handleClick(ClickEvent event) {
//do stuff
}
I get an error, because I have 3 methods with the same name. Is there a way around this, other than creating custom widgets and add those to the VerticalPanel?
There is also an option to use one annotation for multiple Widgets
@UiHandler(value={"clearButton_1", "clearButton_2"})
void handleClickForLabel1(ClickEvent event) {
//do stuff
}
Just name them different things. The important part that helps GWT recognize what kind of event you want to handle is the ClickEvent
, but the method name doesn't matter.
@UiHandler("Label1")
void handleClickForLabel1(ClickEvent event) {
//do stuff
}
@UiHandler("Label2")
void handleClickForLabel2(ClickEvent event) {
//do stuff
}
@UiHandler("Label3")
void whoaSomeoneClickedLabel3(ClickEvent event) {
//do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With