【问题标题】:GWT-Bootstrap Modal not shown after setVisible is called调用 setVisible 后未显示 GWT-Bootstrap 模态
【发布时间】:2013-02-26 21:02:22
【问题描述】:

我有一个简单的模式,我想在单击按钮时显示它。

这是我用来显示模态的代码

@UiHandler("submit")
void handleClick(ClickEvent e){
    ModalDialogDemo modalDialog = (ModalDialogDemo) RootPanel.get().getWidget(2);
    modalDialog.setHeight("200px");
    modalDialog.setWidth("100px");
    modalDialog.setVisible(true);
    if(modalDialog.isVisible()){
        System.out.println("Successfully Displayed the Modal!");
    }
    else{
        System.out.println("Something went wrong.");
    }
}

即使模态没有显示在屏幕上,登录到控制台的消息是前者,即成功显示模态!

我用 firebug 进行了一些挖掘,在单击按钮之前呈现的 HTML 是

<div>
<div class="modal" style="display: none;" aria-hidden="true">
<div class="modal-header"><a class="close" data-dismiss="modal">×</a><h3>Name</h3></div>
<div class="modal-body"><div class="gwt-Label">Modal Content Comes Here</div></div>
<div class="modal-footer"><div class="gwt-Label">And this is the footer</div></div></div>
</div>

点击按钮后变为

<div style="height: 200px; width: 100px;" aria-hidden="false">
<div class="modal" style="display: none;" aria-hidden="true">
<div class="modal-header"><a class="close" data-dismiss="modal">×</a><h3>Name</h3></div>
<div class="modal-body"><div class="gwt-Label">Modal Content Comes Here</div></div>
<div class="modal-footer"><div class="gwt-Label">And this is the footer</div></div></div>
</div>

第一个 div 应用了我设置的高度和宽度,并且 aria-hidden 也被清除,但实际包含模态的子 div 不受影响。

我不知道如何告诉 GWT 也将更改应用到子 div,有人可以帮我解决这个问题吗?

编辑: 这是我的 ModalDialogDemo.ui.xml

<!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:b = "urn:import:com.github.gwtbootstrap.client.ui">
    <g:HTMLPanel>
        <b:Modal title="VipName" backdrop="STATIC">
            <g:Label>Modal Content Comes Here</g:Label>
            <b:ModalFooter>
                <g:Label>And this is the footer</g:Label>
            </b:ModalFooter>
        </b:Modal>
    </g:HTMLPanel>
</ui:UiBinder> 

【问题讨论】:

    标签: gwt modal-dialog gwt-bootstrap


    【解决方案1】:

    您需要在 GWT-Bootstrap 模态对象上调用 show() 方法来显示它。

    更新:

    在ui.xml文件中,为modal分配一个id。

    <b:Modal title="VipName" ui:field="vipNameModel" backdrop="STATIC">
    

    在 ModalDialogDemo.JAVA 文件中,获取该对象。

    @UiField
        Modal vipNameModel;
    

    创建getter方法:

    Modal getVipNameModel()
    {
    return vipNameModel'
    }
    

    然后从 ModalDialogDemo 类调用 modalDialog.getVipNameModel().show();

    【讨论】:

    • @nikhil 请看你提到的 api 文档。 public void show(): Shows the widget if it was previously hidden. 尝试使用它。我用它来显示模式,使用 gwt-bootstrap-2.2.1.0-SNAPSHOT.jar。你用的是哪个版本?
    • 我认为你是对的@takrbuiam 我也添加了我的 UIBinder 代码。如何从 ModalDialogDemo 类中选择 Modal?如果我能够选择它,那么我就可以打电话给show。对此有任何指示吗?
    • 非常感谢这确实是问题所在,现在我知道了,我觉得自己很愚蠢。感谢您抽出宝贵时间帮助解决此问题。
    猜你喜欢
    • 2015-10-31
    • 2021-08-04
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    相关资源
    最近更新 更多