简体   繁体   中英

Button Submit in Vaadin

I am Using Vaadin in my application to display the REPORTS on PAGED TABLE from date to to date.

The code is working fine, when I click the submit button the data is not showing any where on vaadin ui table but, when I click the header row of that table then the data is showing.I need when the user entered from date to to date then after clicking the submit button the I need to display the reports on table instead of clicking the header row.Here I am top display the reports on the table I am using PAGED TABLE instead of normal Table.

I am using this Code for all reports due to this all reports are behaving likesame.

Pls help me here is the code is

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();
            }

        }
    });

}

I think that your HibernateUtils.getCurrentSession().doWork(new Work().... is starting a background thread and, when the report is finished fills in the table.

For background threads updating the UI in vaadin, there a special rules on how to do it. When you don't follow them, then the serverside changes are only visible on the next client->server interaction.

https://vaadin.com/book/vaadin7/-/page/advanced.push.html#advanced.push.running

Don't forget to also look at server push/polling, since the webbrowser must be notified for the new content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM