0

I'm using a Popover component of the GWtBootstrap - org.gwtbootstrap3.client.ui.Popover. I need to add few Clickable images that invoke java method. As popover does not let you add any widget to its content, I can use the following code to add links

final Popover popover = new Popover();
final SafeHtml html = new SafeHtmlBuilder().appendHtmlConstant("<a href='' title='test add link'>link on content</a>").toSafeHtml();
popover.setHtml(html);

then invoking the Java method using one of the solution here Calling GWT Java function from JavaScript

But whole of this looks little ugly, I also think adding links/images using raw html is very fragile and will be vulnerable.

Is there any better way to have Popover's content having GWT widgets so that we can better control them, may be extending the Popover class could be one option. Any suggestions/hints/solution will be of great help.

chitresh sirohi
  • 275
  • 1
  • 14

1 Answers1

0

One solution to this problem is to create a proper GWT button (ButtonA) outside the popover that do the same action as you want with the button in the popover. Using the html code like the following we can create a button that in turn clicks the ButtonA. I used something like this method to do it.

Popover createPopoverWithButton(Runnable buttonAAction, String id)
{
    SafeHtml popoverButtonHtml= new SafeHtmlBuilder()
                .appendHtmlConstant("<button type=\"button\" id=\"myPopoverButton\" onclick=\"document.getElementById(\'" + id
                        + "\').click()\">Click to invoke java method</button>");
    Popover popover = new Popover("Title", popoverButtonHtml.asString());
    Button buttonA = new Button();
    buttonA.setId(id);
    buttonA.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(final ClickEvent event) {
                buttonAAction.run();
            }

        });
        buttonA.setVisible(false);
   return popover;
}

As I said earlier that this is an improvement over the initial approach that I described in the question. Any improvement over this are most welcome as this solution still have HTML/Javascript which we intend to avoid in GWT.

chitresh sirohi
  • 275
  • 1
  • 14