ZK消息框确认
ZK Message Box Confirmation
我在使用 ZK 时发现了一些奇怪的行为。代码:
@Listen("onClick = button#load")
public void load() {
int result = Messagebox.show("Are you sure to execute Load?", "Execute?",
Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
log.debug("Result: {}", result);
if (result == Messagebox.YES) {
(new Thread(new Job("Load"))).start();
message.setValue("Job " + "Load " + " is Executed at " + new Date());
log.info("Load Called");
} else {
log.debug("Load Not Called");
}
}
点击是或否,它return1作为int。日志:
02-Oct-2016 23:59:31.725 FINE [http-nio-8080-exec-1] com.Controller.load Result: 1
02-Oct-2016 23:59:31.726 FINE [http-nio-8080-exec-1] com.Controller.load Load Not Called
02-Oct-2016 23:59:39.541 FINE [http-nio-8080-exec-6] com.Controller.load Result: 1
02-Oct-2016 23:59:39.542 FINE [http-nio-8080-exec-6] com.Controller.load Load Not Called
如何正确设置?
您使用的是哪个版本的 ZK?
javadoc 说:
@return the button being pressed (one of {@link #OK}, {@link #CANCEL},
{@link #YES}, {@link #NO}, {@link #ABORT}, {@link #RETRY}, and {@link #IGNORE}).
Note: if the event processing thread is disabled, it always returns
{@link #OK}.
但是如果你检查关于事件处理线程的documentation,它说:
[Since ZK 7.0.0 deprecated to enable the event thread according to Java Servlet Specification that may prohibit the creation of new threads]
所以应该通知 ZK 更新它的 javadoc,就好像你使用的是 ZK7 或 8 方法总是 return 1 马上。
为了回答您的问题,如果您想根据单击的按钮调用特定操作:
@Listen("onClick = button#load")
public void load() {
Messagebox.show("Are you sure to execute Load?", "Execute?", Messagebox.YES | Messagebox.NO,
Messagebox.QUESTION, new EventListener<Event>() {
@Override
public void onEvent(final Event evt) throws InterruptedException {
if (Messagebox.ON_YES.equals(evt.getName())) {
// Code if yes clicked
} else {
// Code if no clicked
}
}
}
);
}
我在使用 ZK 时发现了一些奇怪的行为。代码:
@Listen("onClick = button#load")
public void load() {
int result = Messagebox.show("Are you sure to execute Load?", "Execute?",
Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
log.debug("Result: {}", result);
if (result == Messagebox.YES) {
(new Thread(new Job("Load"))).start();
message.setValue("Job " + "Load " + " is Executed at " + new Date());
log.info("Load Called");
} else {
log.debug("Load Not Called");
}
}
点击是或否,它return1作为int。日志:
02-Oct-2016 23:59:31.725 FINE [http-nio-8080-exec-1] com.Controller.load Result: 1
02-Oct-2016 23:59:31.726 FINE [http-nio-8080-exec-1] com.Controller.load Load Not Called
02-Oct-2016 23:59:39.541 FINE [http-nio-8080-exec-6] com.Controller.load Result: 1
02-Oct-2016 23:59:39.542 FINE [http-nio-8080-exec-6] com.Controller.load Load Not Called
如何正确设置?
您使用的是哪个版本的 ZK?
javadoc 说:
@return the button being pressed (one of {@link #OK}, {@link #CANCEL}, {@link #YES}, {@link #NO}, {@link #ABORT}, {@link #RETRY}, and {@link #IGNORE}).
Note: if the event processing thread is disabled, it always returns {@link #OK}.
但是如果你检查关于事件处理线程的documentation,它说:
[Since ZK 7.0.0 deprecated to enable the event thread according to Java Servlet Specification that may prohibit the creation of new threads]
所以应该通知 ZK 更新它的 javadoc,就好像你使用的是 ZK7 或 8 方法总是 return 1 马上。
为了回答您的问题,如果您想根据单击的按钮调用特定操作:
@Listen("onClick = button#load")
public void load() {
Messagebox.show("Are you sure to execute Load?", "Execute?", Messagebox.YES | Messagebox.NO,
Messagebox.QUESTION, new EventListener<Event>() {
@Override
public void onEvent(final Event evt) throws InterruptedException {
if (Messagebox.ON_YES.equals(evt.getName())) {
// Code if yes clicked
} else {
// Code if no clicked
}
}
}
);
}