2

我的目标是创建一个具有几个输入字段和提交按钮按下的简单功能的模式。我想使用这个 gwtbootstrap3 模态: http ://gwtbootstrap3.github.io/gwtbootstrap3-demo/snapshot/#modals 。是否有任何示例如何创建简单的模态,withUiBinder会在按钮单击时弹出?

4

2 回答 2

3

好吧,这正是您在问题中提到的演示中发生的事情。查看它的源代码(查看Modal*文件)以了解它是如何完成的:

// createModal is a Button
createModal.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(final ClickEvent event) {
        final Modal modal = new Modal();
        modal.setTitle("Java Created Modal");
        modal.setClosable(true);

        // Removed modal's event handlers for brevity
        // ...

        final ModalBody modalBody = new ModalBody();
        modalBody.add(new Span("Create in Java Code!"));

        final ModalFooter modalFooter = new ModalFooter();
        modalFooter.add(new Button("Click ME!", new ClickHandler() {
            @Override
            public void onClick(final ClickEvent event) {
                final Paragraph logEntry = new Paragraph();
                logEntry.setText("Click Event from Modal! (Java Created Modal)");
                logRow.add(logEntry);
            }
        }));

        modal.add(modalBody);
        modal.add(modalFooter);

        modal.show();
    }
});
于 2015-03-24T10:44:45.100 回答
1

这是我的解决方案,如何使用 创建ModalUiBinder以防初学者寻找简单的答案:

模态.ui.xml:

<b:Modal closable="true" dataKeyboard="true" ui:field="myModal">
    <b:ModalHeader>
        ..
    </b:ModalHeader>
    <b:ModalBody>
        ...
    </b:ModalBody>
</b:Modal>

模态.java

import org.gwtbootstrap3.client.ui.Modal;


public class MyModal{

    @UiField
    Modal myModal;

    interface ModalViewUiBinder extends UiBinder<Widget,MyModal> {
    }

    private static ModalViewUiBinder uiBinder = GWT
            .create(ModalViewUiBinder.class);

    public MyModal() {
        uiBinder.createAndBindUi(MyModal.this);
    }

    public void show() {
        myModal.show();
    }
}

并点击按钮:

MyModal modal = new MyModal();
modal.show();
于 2015-03-24T10:56:37.800 回答