Reputation: 385
My goal is create a modal with a few input fields and simple functionality on submit button press. I wanna use this gwtbootstrap3 modal :
http://gwtbootstrap3.github.io/gwtbootstrap3-demo/snapshot/#modals . Is there any example how to create simple modal, with UiBinder
, which would pop up on button click ?
Upvotes: 2
Views: 1020
Reputation: 385
Here is my solution, how to create Modal
with UiBinder
, in case there will be starters looking for easy answer:
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();
}
}
and on button click :
MyModal modal = new MyModal();
modal.show();
Upvotes: 1
Reputation: 15321
Well, that's exactly what's happening in the demo you've mentioned in your question. Have a look at it's source code (look at the Modal*
files) to see how it can be done:
// 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();
}
});
Upvotes: 3