GWT UiHandler for g: Anchor does not shoot

I have a menu where you can’t click on the headings, but when you hover over a menu item, you can choose from the drop-down items. Each of the elements: g: Anchor tags with associated fields ui. I would expect that when the user clicks on one of the dropdowns, my uiHandler for this field will fire. Even with debugging and a breakpoint, it never hit.

Below you will find the main areas of concern in the code. I will publish only my import of gwt, as it can be assumed that the rest are correct due to zero errors.

Here is an XML snippet to get an idea of ​​what's going on

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:cpcw='urn:import:org.collegeboard.pa.gwt.client.widget'> <cpcw:ExtendedHTMLPanel> <ul> <li ui:field="juniorHigh"><g:Anchor href="">Junior High</g:Anchor> <ul> <li><g:Anchor href="#" ui:field="juniorHighFall">Fall</g:Anchor></li> <li><g:Anchor href="#" ui:field="juniorHighSpring">Spring</g:Anchor></li> <li><g:Anchor href="#" ui:field="juniorHighSummer">Summer</g:Anchor></li> </ul> </li> </ul> </cpcw:ExtendedHTMLPanel> </ui:UiBinder> 

And here are the parts from my Java class

Import

 import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.LIElement; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.ui.Anchor; 

Ui fields

 @UiField protected LIElement juniorHigh; @UiField protected Anchor juniorHighFall; @UiField protected Anchor juniorHighSpring; @UiField protected Anchor juniorHighSummer; 

Ui handler

 @UiHandler({"juniorHighFall","juniorHighSpring","juniorHighSummer"}) public void handleMenuClick(ClickEvent event) { DisplayUtil.displayAlertMessage(event.toString()); } 

Initialize

 @Override public void initializeBinder() { initWidget(ourUiBinder.createAndBindUi(this)); } 

Now UiHandler never hits the target. I had g: Anchor tags with and without href, and also tried them as g: Hyperlink and g: Button without success. It is as if UiHandler is not even there.

Any help would be greatly appreciated, and if you feel that you need anything else to troubleshoot, please let me know.

Thanks: -)

EDIT:

To make sure this was clear, the template ui.xml file containing this ui.xml file placed it in a div. When I replaced this with SimplePanel, everything worked with UiHandler.

Thanks for answers!

+6
source share
2 answers

This works and should work on its own.

I noticed:

  • Links to your "ourUiBinder" code
  • Your controls are wrapped in an "ExtendedHTMLPanel"

This is similar to user classes - maybe something funky is happening in these implementations?

Perhaps you can try wrapping these bindings in SimplePanel and using the default UiBinder and see if this works. If so, this is most likely due to any custom controls you use. If this is not the case, something strange happens - maybe restart your IDE, etc.

+6
source

In the Template XML file, each view was contained in a div element. Filip-fku recommended that I look at SimplePanels for the code I posted and make me look at the template file to see that they were not GWT containers at all, they were divs. Once I made them SimplePanels, my UiHandlers worked like a charm!

Thank Philippe g: SimplePanel FTW !!!

+2
source

Source: https://habr.com/ru/post/897787/


All Articles