How to refresh vaadin table after altering data?

Refresh

April 2019

Views

48 time

1

I have this vaadin table which i'm using to display and update records that are being stored in MySQL DB, it all works fine except for updating the table after making a modification or an update, I tried using Table.refreshRowCache() but that wasn't useful

 try{
            Class.forName("com.mysql.jdbc.Driver");
            Core.con = DriverManager.getConnection(Core.db,Core.dbUsername,Core.dbPassword);
            java.sql.Statement st = Core.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
            ResultSet rs = st.executeQuery(Core.Show);

            while(rs.next()){
                table.addItem(new Object[]{rs.getInt(1), rs.getString(2), rs.getDate(3)},rs.getInt(1));

            }
        }catch(Exception e){
            e.printStackTrace();
        }

        table.addItemClickListener(new ItemClickEvent.ItemClickListener(){

            @Override
            public void itemClick(ItemClickEvent event) {
                Name = new TextField("Name");
                Name.setRequired(true);
                TextField Name1 = new TextField("Name");
                Name1.setVisible(false);
                Date = new DateField("Date");
                Date.setDateFormat("yyyy-MM-dd");
                Date.setRequired(true);
                DateField Date1 = new DateField("Date");
                Date1.setDateFormat("yyyy-MM-dd");
                Date1.setVisible(false);
                Id = new TextField();
                Id.setVisible(false);


                Name.setValue((String) event.getItem().getItemProperty("Name").getValue());
                Name1.setValue((String) event.getItem().getItemProperty("Name").getValue());
                Date.setValue((Date)event.getItem().getItemProperty("Date").getValue());
                Date1.setValue((Date)event.getItem().getItemProperty("Date").getValue());

                Save = new Button("Save");
                Save.setStyleName("small");
                Save.setStyleName("primary");
                Save.setSizeUndefined();

                Save.addClickListener(new Button.ClickListener(){

                    @Override
                    public void buttonClick(ClickEvent event) {
                        try{
                            Class.forName("com.mysql.jdbc.Driver");
                            Core.con = DriverManager.getConnection(Core.db,Core.dbUsername,Core.dbPassword);
                            Core.stmt = Core.con.prepareStatement(Core.Replace);
                            Core.statement = Core.con.prepareStatement(Core.ReplaceDate);
                            Core.stmt.setString(1,Name.getValue().toString());
                            Core.stmt.setString(2,Name1.getValue().toString());
                            Core.stmt.setDate(3,new java.sql.Date(Date1.getValue().getTime()));
                            Core.statement.setDate(1,new java.sql.Date(Date.getValue().getTime()));
                            Core.statement.setString(2,Name1.getValue().toString());
                            Core.statement.setDate(3,new java.sql.Date(Date1.getValue().getTime()));
                            Core.stmt.executeUpdate();
                            Core.statement.executeUpdate();
                            Notification.show("done");
                            Name.setVisible(false);
                            Date.setVisible(false);
                            Save.setVisible(false);
                            Delete.setVisible(false);
                        }catch(Exception e){
                            e.printStackTrace();
                        }

                    }

                });

                Delete = new Button("Delete");
                Delete.setStyleName("small");
                Delete.setStyleName("danger");
                Delete.setSizeUndefined();

                Delete.addClickListener(new Button.ClickListener(){
                    @Override
                    public void buttonClick (ClickEvent ev){
                        try{
                            Class.forName("com.mysql.jdbc.Driver");
                            Core.con = DriverManager.getConnection(Core.db,Core.dbUsername,Core.dbPassword);
                            Core.stmt = Core.con.prepareStatement(Core.Delete);
                            Core.stmt.setString(1,Name1.getValue().toString());
                            Core.stmt.setDate(2,new java.sql.Date(Date1.getValue().getTime()));
                            Core.stmt.executeUpdate();
                            Notification.show("done");
                            Name.setVisible(false);
                            Date.setVisible(false);
                            Save.setVisible(false);
                            Delete.setVisible(false);
                        }catch(Exception ex){
                            Notification.show(ex.getMessage());
                        }
                    }
                });


                show.addComponent(Name);
                show.addComponent(Date);
                Edit.addComponent(Save);
                Edit.addComponent(Delete);
                show.setSpacing(true);
                show.addComponent(Edit);



            }

        });

As stated in the title I'd apreciate a solution to update the rows after making the modification.

0 answers