On Sunday, December 12, 2010 2:59:18 PM UTC+1, Noor wrote:
Hi, I want to add a click handler to an anchor defined in an gwt html
panel with no success. I am using the following method
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);
(particularly comment #9 and #18)
In your case, how about using HTMLPanel to *insert* your Anchor within the HTML (replacing, say, a <span> used as a placeholder)?
That being said, Anchor (<a> in HTML) is not the right tool for the job. You should only use a link to... link to something (i.e. use its href="" attribute); otherwise, use a Label or whatever and eventually style it to make it look like a link.
As for UiBinder, it would allow you to write your HTML fragment as XML (instead of a string literal in Java code) and directly embed the Anchor widget in the HTML instead of doing yourself the placeholder+replace dance (UiBinder would generate it for you):
<g:HTMLPanel>
<div class='BackHeader'>Selected
Attribute:Select an Attribute to edit(<g:Anchor ui:field='DeleteCategory'>Delete
this Attribute</g:Anchor>>)</div>
</g:/HTMLPanel>
And for handling the ClickEvent, you can then use an @UiHandler method in the owner class:
@UiHandler('DeleteCategory')
void onDeleteCategoryClick(ClickEvent event) { ... }