I use GWTBootstrap3 v0.9.1.
I want to display a Popover with content that is stored in database. So when user hovers an element for the first time a Popover is displayed with Please wait...
info. Meanwhile I get the proper text from database and want to replace Popover's content with a new one.
I thought this code would do the trick:
popover.setContent(newText);
popover.reconfigure();
But it doesn't work: the popover disappears and is not displayed anymore.
I know there are solutions for Bootstrap users, but as I use GWT-Bootstrap I want to do it in GWT without using jQuery.
I follow @Knarf's suggestion and use native method as I could not find pure GWT solution:
private native void updatePopover(Element element, String popoverHtml, boolean shown) /*-{
var $popover = $wnd.jQuery(element);
$popover.data('bs.popover').options.content = popoverHtml;
if(shown)
$popover.popover('show');
}-*/;
where:
element
is the popover widget's element (the element that has the popover)popoverHtml
is the new contentshown
indicates whether popover is visible during updateI keep track of visible state by ShowHandler and HideHandler:
uiPopover.addShowHandler(new ShowHandler() {
@Override
public void onShow(ShowEvent event) {
popoverVisible = true;
}
});
uiPopover.addHideHandler(new HideHandler() {
@Override
public void onHide(HideEvent event) {
popoverVisible = false;
}
});
EDIT: It's better to use ShowHandler and HideHandler instead of ShownHandler and HiddenHandler.