簡體   English   中英

按鈕在Vaadin中提交

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM