[英]Button Submit in Vaadin
我在我的应用程序中使用Vaadin来显示PAGED TABLE上迄今为止的报告。
代码运行正常,当我单击``提交''按钮时,数据没有显示在vaadin ui表上的任何位置,但是当我单击该表的标题行时,则显示了数据。当用户输入从日期到日期,然后单击“提交”按钮后,我需要在表格上显示报告,而不是单击标题行。在这里,我将使用PAGED TABLE而不是普通表在表格的顶部显示报告。
由于所有报告的行为都相同,因此我正在对所有报告使用此代码。
请帮我这里的代码是
Button executeReportButton = new Button("Submit");
executeReportButton.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if ((Date) tatFromDate.getValue() != null
&& (Date) tatToDate.getValue() != null) {
runDBReport(reportTable, (Date) tatFromDate.getValue(),
(Date) tatToDate.getValue());
} else
showWarningNotification("Error loading check list report.",
"Date entered is not valid.");
}
});
private void runDBReport(PagedTable reportTable, Date fromDate, Date toDate) {
final PagedTable _reportTable = reportTable;
final Date _fromDate = fromDate;
final Date _toDate = toDate;
HibernateUtils.getCurrentSession().doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
String reportCall = "{ call RP_PROC_CHECKLIST_AUDIT(?, ?, ?) }";
CallableStatement stmt = null;
ResultSet rs = null;
try {
stmt = connection.prepareCall(reportCall);
// register the type of the out param - an Oracle specific
// type
stmt.registerOutParameter(3, OracleTypesHelper.INSTANCE
.getOracleCursorTypeSqlType());
// set the in param
stmt.setDate(1, new java.sql.Date(_fromDate.getTime()));
stmt.setDate(2, new java.sql.Date(_toDate.getTime()));
// execute and retrieve the result set
stmt.execute();
rs = (ResultSet) stmt.getObject(3);
// get the results
while (rs.next()) {
Object TATDataRowId = _reportTable.addItem();
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistid")
.setValue(rs.getString(1));
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistdescription")
.setValue(rs.getString(2));
// ... a trillion more
}
} catch (Exception e) {
logger.error(
"Error loading check list report. Exception: {}",
e.getMessage());
logger.debug("Error loading check list report.", e);
showWarningNotification(
"Error loading check list report. Please contact admin",
"Error message is : " + e.getMessage());
} finally {
rs.close();
stmt.close();
}
}
});
}
我认为您的HibernateUtils.getCurrentSession()。doWork(new Work()....正在启动后台线程,并且当报告完成时会填入表格。
对于在vaadin中更新UI的后台线程,有专门的规则来做到这一点。 如果不遵循它们,则服务器端更改仅在下一次客户端->服务器交互中可见。
https://vaadin.com/book/vaadin7/-/page/advanced.push.html#advanced.push.running
不要忘记也要查看服务器的推送/轮询,因为必须通知Web浏览器新内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.