您可以使用其他通知系统并运行异步 JavaScript 代码。您也可以在 10 分钟内包装任何其他通知系统(实现 Vaadin AbstractJavaScriptComponent),例如noty2(使用时应包含 jQuery 库):http ://needim.github.io/noty/
并在执行操作时显示通知,例如这个:
new Notty("WARNING<br>description... (static)", Notty.Type.WARNING).show(UI.getCurrent());
new Notty("WARNING<br>description... (close in 3000ms)", Notty.Type.WARNING, 3000).show(UI.getCurrent());
new Notty("WARNING<br>description... (modal)", Notty.Type.WARNING, 0, true).show(UI.getCurrent());
new Notty("WARNING<br>description... (modal force, close in 3000ms)", Notty.Type.WARNING, 3000, true, true).show(UI.getCurrent());
new Notty("asd", Notty.Type.ERROR, 5000).show(UI.getCurrent());
package user_interface.util.ext;
import com.vaadin.annotations.JavaScript;
import com.vaadin.ui.AbstractJavaScriptComponent;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.UI;
import java.io.Serializable;
import java.util.Iterator;
public class Notty implements Serializable {
private String message;
private String type;
private int closeIn = 0;
private boolean force = false;
private boolean modal = false;
public Notty(String message, Notty.Type type) {
this.message = message;
this.type = type.value;
}
public Notty(String message, Notty.Type type, int closeIn) {
this.message = message;
this.type = type.value;
this.closeIn = closeIn;
}
public Notty(String message, Notty.Type type, int closeIn, boolean modal) {
this.message = message;
this.type = type.value;
this.closeIn = closeIn;
this.modal = modal;
}
public Notty(String message, Notty.Type type, int closeIn, boolean modal, boolean force) {
this.message = message;
this.type = type.value;
this.closeIn = closeIn;
this.modal = modal;
this.force = force;
}
public void show(UI ui) {
AbstractOrderedLayout aol = (AbstractOrderedLayout) ui.getContent();
NottyMessage nm = null;
boolean wasAdded = false;
Iterator itr = aol.iterator();
while(itr.hasNext()) {
Object o = itr.next();
if (o instanceof NottyMessage) {
nm = (NottyMessage) o;
wasAdded = true;
}
}
if (!wasAdded) {
nm = new NottyMessage();
aol.addComponent(nm);
}
nm.show(message, type, closeIn, force, modal);
}
@JavaScript({"NottyMessage.js"})
private class NottyMessage extends AbstractJavaScriptComponent {
public NottyMessage() {
setImmediate(true);
}
@Override
protected NottyMessageState getState() {
return (NottyMessageState) super.getState();
}
private void show(String mess, String type, int closeIn, boolean force, boolean modal) {
callFunction("show", mess, type, closeIn, force, modal);
}
}
public static enum Type {
ALERT("alert"),
INFORMATION("information"),
ERROR("error"),
WARNING("warning"),
NOTIFICATION("notification"),
SUCCESS("success");
private String value;
private Type(String val) {
this.value = val;
}
}
}
NottyMessageState.java
package user_interface.util.ext;
import com.vaadin.shared.ui.JavaScriptComponentState;
public class NottyMessageState extends JavaScriptComponentState {
public String xhtml;
public String type;
}
NottyMessage.js
user_interface_util_ext_Notty_NottyMessage = function() {
var e = this.getElement();
this.onStateChange = function() {
// change state callb
}
this.show = function(message, messageType, closeInMs, isForce, isModal) {
var n = noty({
text: message,
type: messageType,
dismissQueue: true,
timeout: closeInMs,
force: isForce,
modal: isModal,
maxVisible: 7,
layout: "bottomLeft",
theme: "defaultTheme"
});
}
}
它应该是这样的: