我的目标是在提交按钮按下时创建一个带有几个输入字段和简单功能的模态。我想使用这个gwtbootstrap3模式:
http://gwtbootstrap3.github.io/gwtbootstrap3-demo/snapshot/#modals。有没有任何示例如何使用UiBinder
创建简单的模态,它会在按钮点击时弹出?
答案 0 :(得分:3)
嗯,这正是您在问题中提到的演示中发生的事情。查看it's source code(查看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();
}
});
答案 1 :(得分:1)
以下是我的解决方案,如何使用Modal
创建UiBinder
,以防初学者寻找简单的答案:
Modal.ui.xml:
<b:Modal closable="true" dataKeyboard="true" ui:field="myModal">
<b:ModalHeader>
..
</b:ModalHeader>
<b:ModalBody>
...
</b:ModalBody>
</b:Modal>
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();