Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT UiHandler for g:Anchor is not firing

Tags:

gwt

I essentially have a menu where you can't click the headers, but when you hover over the menu item you can select from the drop down elements. Each of the elements are g:Anchor tags with ui fields associated to them. What I would expect to happen, is that when a user clicks on one of the drop down elements, my uiHandler for that field would fire. Even with debugging on and a break point it doesn't ever hit.

Below you will find the main areas of concern in the code. I will only post my gwt imports in here, since it can be assumed the rest are correct due to zero errors.

Here is an XML snippet to get an idea of what is 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 then here are the pieces from my Java class

imports

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, the UiHandler never actually gets hit. I have had the g:Anchor tags with and without the href, and also have tried them as g:Hyperlink and g:Button with no success. It is as if the UiHandler isn't even there.

Any help would be greatly appreciated, and also if you feel you would need anything else for troubleshooting, please let me know!!

Thanks :-)

EDIT:

Just to make sure that this was clear, the template ui.xml file that contained this ui.xml file was placing this in a div. When I replaced that with a SimplePanel, everything worked with the UiHandler.

Thanks for the responses!

like image 597
tklives Avatar asked Sep 21 '11 23:09

tklives


1 Answers

This does and should work as you have it by default.

I've noticed:

  • Your code references "ourUiBinder"
  • Your controls are wrapped in a "ExtendedHTMLPanel"

These seem like custom classes - perhaps something funky is going on in those implementations?

Maybe you can try wrapping those anchors in a SimplePanel and using the default UiBinder and see if that works. If it does, chances are it's something to do with any custom controls you use. If it doesn't then something strange is going on - maybe restart your IDE etc.

like image 144
filip-fku Avatar answered Sep 23 '22 23:09

filip-fku