【问题标题】:GWT Popup and UIBinder: Panel or DialogBox?GWT 弹出窗口和 UIBinder:面板还是对话框?
【发布时间】:2011-08-02 13:46:26
【问题描述】:

我有一个要求,当单击按钮时,应使用弹出/对话框提示用户输入一些其他详细信息,例如姓氏、出生日期等。我尝试使用window.confirm(),但我认为这不符合我的目的。有人可以帮助我如何通过 UIBinder 在 GWT 中实现这一点吗?

我在我的 UI binder.xml 中尝试了类似的操作

<g:HTMLPanel visible="false" >
                                    <g:DialogBox ui:field="dialogPanel"
                                        animationEnabled="true" modal="false" glassEnabled="false">
                                        <g:caption>More Details</g:caption>
                                        <table>
                                            <tr>
                                                <td colspan="2" align="center">
                                                    <g:Datepicker ui:field="DOB">DOB:</g:Datepicker>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td>UserName:</td>
                                                <td>
                                                    <g:TextBox ui:field="usernameTextBox" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td align="right">
                                                    <g:Button ui:field="loginButton">OK</g:Button>
                                                </td>
                                            </tr>
                                        </table>
                                    </g:DialogBox>
                                </g:HTMLPanel>

我不确定要使用哪一个:弹出窗口还是对话框!

谢谢。

【问题讨论】:

    标签: gwt uibinder


    【解决方案1】:

    这是使用 uibinder 的 GWT 对话框的框架:

    MyDialogBox.java

    import com.google.gwt.core.client.GWT;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.user.client.ui.DialogBox;
    import com.google.gwt.user.client.ui.Widget;
    
    public class MyDialogBox extends DialogBox {
        private static final Binder binder = GWT.create(Binder.class);
        interface Binder extends UiBinder<Widget, MyDialogBox> {
        }
        public MyDialogBox() {
            setWidget(binder.createAndBindUi(this));
            setAutoHideEnabled(true);
            setText("My Title");
            setGlassEnabled(true);
             center();
        } 
    }
    

    MyDialog.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'>
        <ui:style>
            .panel {
                background-color: ivory;
            }
        </ui:style>
        <g:FlowPanel styleName="{style.panel}">
        <g:Label>Dialog Content</g:Label>
        </g:FlowPanel>
        </ui:UiBinder>
    

    显示它使用:

    MyDialogBox m = new MyDialogBox();
    m.show();
    

    【讨论】:

      【解决方案2】:

      DialogBoxPopupPanel 的子代,具有它的所有功能。此外,它具有(来自文档):

      ..caption area at the top and can be dragged by the user.
      

      关于 UiBinder 中的使用(同样来自文档):

      DialogBox elements in UiBinder templates can have one widget child and one 
      <g:caption> child.
      

      因此,您似乎需要将 &lt;table&gt; 替换为 GWT 小部件,很可能是 &lt;g:HTMLPanel&gt;,并将整个 &lt;table&gt; 放入其中。

      此外,PopupPanel 和 DialogBox 是独立的小部件,通常不会添加到其他小部件,但通过 .show()hide() 方法显示。所以,在你的 UiBinder 中,你可以把 &lt;g:DialogBox&gt; 在根级别。

      【讨论】:

      • 嗨,谢谢您的回复。我只需稍作改动就能完成这项工作。我仍然将 Html 包裹在对话框标签周围。我不得不在我的内部调用 dialogBox.center() UiHandler 方法。
      猜你喜欢
      • 2021-09-13
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多