0
當數據庫發生某些更改時,如何更新UI上的數據? 我想讓我的用戶界面自動更新數據,當我更改我的數據庫(使用通用數據庫查看器)記錄時,就像Facebook有人在剪貼板上發佈內容時一樣(無需刷新)關於數據庫數據更改的ZK UI更新
當數據庫發生某些更改時,如何更新UI上的數據? 我想讓我的用戶界面自動更新數據,當我更改我的數據庫(使用通用數據庫查看器)記錄時,就像Facebook有人在剪貼板上發佈內容時一樣(無需刷新)關於數據庫數據更改的ZK UI更新
您可以使用輪詢或推送。
推可以擴展SelectorComposer 並適用於你ZUL
public class ComposerPush extends SelectorComposer<Component> {
private static final long serialVersionUID = 1L;
// wire components
@Wire
ZHighCharts chartComp;
// Basic Line
private SimpleExtXYModel dataChartModel = new SimpleExtXYModel();
public void startWorker() {
final Desktop desktop = Executions.getCurrent().getDesktop();
if (desktop.isServerPushEnabled()) {
} else {
desktop.enableServerPush(true);
if(timer != null)timer.cancel();
timer = new Timer();
timer.schedule(databaseCheck(), 0, 5000);
}
}
private TimerTask databaseCheck() {
return new TimerTask() {
@Override
public void run() {
updateInfo();
}
};
}
private void updateInfo() {
try {
Desktop desktop = chartComp.getDesktop();
if(desktop == null) {
timer.cancel();
return;
}
Executions.activate(desktop);
try {
**<your code in here>**
} finally {
Executions.deactivate(desktop);
}
} catch (DesktopUnavailableException ex) {
System.out.println("Desktop currently unavailable");
timer.cancel();
} catch (InterruptedException e) {
System.out.println("The server push thread interrupted");
timer.cancel();
}
}
看來,什麼是不完整的在這個例子中... –
@ Tex'N'Duet看到我的增加,您擴展作曲家 – Nikos