Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Refresh Table After Adding New Record
Refreshing the Table after adding a new Record where an each existing row consisting of Button (ie Edit and Delete) which is not comming from the DB.
Please help me on this. I had attached snippet for the UserComponet and AddUserComponet.
public class UserComponent extends Component {
/**
*
*/
private static final long serialVersionUID = 3552096318646002390L;
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private Table userTable;
@Autowire
private UserService userService;
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
/**
* The constructor should first build the main layout, set the composition
* root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the visual
* editor.
*/
public UserComponent() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
}
@AutoGenerated
private AbsoluteLayout buildMainLayout() {
userTable = null;
// common part: create layout
mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);
// top-level component properties
setWidth("100.0%");
setHeight("100.0%");
// table_1
userTable = new Table();
userTable.setImmediate(true);
userTable.setWidth("100.0%");
userTable.setHeight("400px");
userTable.setSelectable(true);
userTable.addContainerProperty("Edit", Button.class, null);
userTable.addContainerProperty("Delete", Button.class, null);
userTable.addContainerProperty("Full Name", String.class, null);
userTable.addContainerProperty("Role", String.class, null);
userTable.addContainerProperty("EmailId", String.class, null);
userTable.addContainerProperty("Status", Boolean.class, null);
userTable.addContainerProperty("Created Date", Date.class, null);
userTable.addContainerProperty("Modified Date", Date.class, null);
// userTable.addListener(new MyListener());
Button deleteButton = new Button();
List<Users> usrList = getUserService().getUserData();
int i = 0;
for (Iterator iterator = usrList.iterator(); iterator.hasNext();) {
mainLayout.removeComponent(userTable);
final Users users = (Users) iterator.next();
CustomButton editButton = new CustomButton("Edit",
new Button.ClickListener() {
/**
*
*/
private static final long serialVersionUID = 8034233094433430666L;
// inline click-listener
public void buttonClick(ClickEvent event) {
Table comp = (Table) event.getButton().getParent();
CustomButton ediButton = (CustomButton) event
.getButton();
// userTable.addListener(new MyListener());
Integer rowId = (Integer) userTable.getValue(); // get
// the
// selected
// rows
// id
if (rowId == null) {
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
mainWindow
.showNotification("please select one row");
} else if (ediButton.getId().equals(rowId)) {
String fullname = (String) userTable
.getContainerProperty(rowId,
"Full Name").getValue();
String role = (String) userTable
.getContainerProperty(rowId, "Role")
.getValue();
String emailId = (String) userTable
.getContainerProperty(rowId, "EmailId")
.getValue();
Boolean status = (Boolean) userTable
.getContainerProperty(rowId, "Status")
.getValue();
Date createdDate = (Date) userTable
.getContainerProperty(rowId,
"Created Date").getValue();
Date modifiedDate = (Date) userTable
.getContainerProperty(rowId,
"Modified Date").getValue();
users.setFirstname(fullname);
users.setLastname(fullname);
users.setRole(role);
users.setEmailid(emailId);
users.setStatus(status);
users.setCreatedDate(createdDate);
users.setModifiedDate(modifiedDate);
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
final Window subwindow = new Window(
"Add New USer");
subwindow.setModal(true);
subwindow.setHeight("290px");
subwindow.setWidth("740px");
mainWindow.addWindow(subwindow);
subwindow.setPositionX(120);
subwindow.setPositionY(120);
VerticalLayout Layout = (VerticalLayout) subwindow
.getContent();
Layout.setImmediate(false);
Layout.setWidth("100%");
Layout.setHeight("100%");
Layout.setMargin(false);
ProfilePasswordComp ac = new ProfilePasswordComp(
users);
subwindow.addComponent(ac);
} else
{
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
mainWindow
.showNotification("Please select the row you want to edit");
}
}
});
CustomButton deletButton = new CustomButton("Delete",
new Button.ClickListener() {
/**
*
*/
private static final long serialVersionUID = 8034233094433430666L;
// inline click-listener
public void buttonClick(ClickEvent event) {
Table comp = (Table) event.getButton().getParent();
CustomButton deletButton = (CustomButton) event
.getButton();
// userTable.addListener(new MyListener());
Integer rowId = (Integer) userTable.getValue();
if (rowId == null) {
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
mainWindow
.showNotification("please select row you want to delete",Notification.TYPE_ERROR_MESSAGE);
} else if (deletButton.getId().equals(rowId)) {
String fullname = (String) userTable
.getContainerProperty(rowId,
"Full Name").getValue();
String role = (String) userTable
.getContainerProperty(rowId, "Role")
.getValue();
String emailId = (String) userTable
.getContainerProperty(rowId, "EmailId")
.getValue();
Boolean status = (Boolean) userTable
.getContainerProperty(rowId, "Status")
.getValue();
Date createdDate = (Date) userTable
.getContainerProperty(rowId,
"Created Date").getValue();
Date modifiedDate = (Date) userTable
.getContainerProperty(rowId,
"Modified Date").getValue();
users.setFirstname(fullname);
users.setLastname(fullname);
users.setRole(role);
users.setEmailid(emailId);
users.setStatus(status);
users.setCreatedDate(createdDate);
users.setModifiedDate(modifiedDate);
//getWindow().showNotification("Are you sure wantto do this", Notification.TYPE_HUMANIZED_MESSAGE);
// for deleting the records
getUserService().deleteUser(users);
userTable.setContainerDataSource(userTable.getContainerDataSource());
userTable.refreshRowCache();
buildMainLayout();
setCompositionRoot(mainLayout);
} else
{
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
mainWindow
.showNotification("Please select the row you want to edit");
}
}
});
deletButton.setId(i);
editButton.setId(i);
String firstName = users.getFirstname();
String lastName = users.getLastname();
String fullName = firstName + lastName;
userTable.addItem(new Object[] { editButton, deletButton, fullName,
users.getRole(), users.getEmailid(), users.isStatus(),
users.getCreatedDate(), users.getModifiedDate() },
new Integer(i));
i++;
}
userTable.refreshCurrentPage();
userTable.refreshRowCache();
mainLayout.requestRepaintAll();
mainLayout.requestRepaint();
mainLayout.setImmediate(true);
mainLayout.addComponent(userTable,
"top:60.0px;right:76.0px;left:20.0px;");
//setCompositionRoot(mainLayout);
userTable.setColumnIcon("Edit", new ThemeResource(
"icons/16/refresh.png"));
// addNewUSer
CustomButton addNewUSer = new CustomButton("Add New User",
new Button.ClickListener() {
private static final long serialVersionUID = 8034233094433430666L;
// inline click-listener
public void buttonClick(ClickEvent event) {
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
final Window subwindow = new Window("Add New USer");
subwindow.setModal(true);
subwindow.setHeight("330px");
subwindow.setWidth("800px");
mainWindow.addWindow(subwindow);
subwindow.setPositionX(120);
subwindow.setPositionY(120);
VerticalLayout Layout = (VerticalLayout) subwindow.getContent();
Layout.setImmediate(false);
Layout.setWidth("100%");
Layout.setHeight("100%");
Layout.setMargin(false);
AddUserComp ac = new AddUserComp();
subwindow.addComponent(ac);
}
});
addNewUSer.setImmediate(true);
addNewUSer.setWidth("-1px");
addNewUSer.setHeight("-1px");
mainLayout.addComponent(addNewUSer, "top:20.0px;left:680.0px;");
//addNewUSer.addListener(new DetailInfoListener());
return mainLayout;
}
public void refrshTabel() {
buildMainLayout();
//this.setCompositionRoot(mainLayout);
}
}
import java.util.Date;
import com.fibersnap.annotations.Autowire;
import com.fibersnap.domain.Users;
import com.fibersnap.service.UserService;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Validator;
import com.vaadin.data.validator.NullValidator;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
public class AddUserComp extends CustomComponent {
/**
*
*/
private static final long serialVersionUID = 1960379728890246869L;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private Button cancelButton;
@AutoGenerated
private Button saveButton;
@AutoGenerated
private ComboBox roleComboBox;
@AutoGenerated
private OptionGroup statusGroup;
@AutoGenerated
private CheckBox checkBox_1;
@AutoGenerated
private PasswordField passwordFieldTxt;
@AutoGenerated
private TextField emailIdTxt;
@AutoGenerated
private TextField lastNameTxt;
@AutoGenerated
private TextField firstNameTxt;
@AutoGenerated
private Label notifyUserLbl;
@AutoGenerated
private Label roleLbl;
@AutoGenerated
private Label lastNameLbl;
@AutoGenerated
private Label passwordLbl;
@AutoGenerated
private Label statusLbl;
@AutoGenerated
private Label emailIDLbl;
@AutoGenerated
private Label firstNameLbl;
@Autowire
private UserService userService;
final String[] roleCombo = new String[] { "ROLE_USER", "ROLE_ADMIN"};
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
/**
* The constructor should first build the main layout, set the
* composition root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the
* visual editor.
*/
public AddUserComp() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
}
@AutoGenerated
private AbsoluteLayout buildMainLayout() {
// common part: create layout
mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("800px");
mainLayout.setHeight("320px");
mainLayout.setMargin(false);
// top-level component properties
// firstNameLbl
firstNameLbl = new Label();
firstNameLbl.setImmediate(false);
firstNameLbl.setWidth("80px");
firstNameLbl.setHeight("-1px");
firstNameLbl.setValue("First Name");
mainLayout.addComponent(firstNameLbl, "top:22.0px;left:40.0px;");
// emailIDLbl
emailIDLbl = new Label();
emailIDLbl.setImmediate(false);
emailIDLbl.setWidth("-1px");
emailIDLbl.setHeight("-1px");
emailIDLbl.setValue("Email ID");
mainLayout.addComponent(emailIDLbl, "top:60.0px;left:40.0px;");
// statusLbl
statusLbl = new Label();
statusLbl.setImmediate(false);
statusLbl.setWidth("-1px");
statusLbl.setHeight("-1px");
statusLbl.setValue("Status");
mainLayout.addComponent(statusLbl, "top:100.0px;left:40.0px;");
// passwordLbl
passwordLbl = new Label();
passwordLbl.setImmediate(false);
passwordLbl.setWidth("-1px");
passwordLbl.setHeight("-1px");
passwordLbl.setValue("Password");
mainLayout.addComponent(passwordLbl, "top:142.0px;left:40.0px;");
// lastNameLbl
lastNameLbl = new Label();
lastNameLbl.setImmediate(false);
lastNameLbl.setWidth("-1px");
lastNameLbl.setHeight("-1px");
lastNameLbl.setValue("Last Name");
mainLayout.addComponent(lastNameLbl, "top:22.0px;left:440.0px;");
// roleLbl
roleLbl = new Label();
roleLbl.setImmediate(false);
roleLbl.setWidth("-1px");
roleLbl.setHeight("-1px");
roleLbl.setValue("Role");
mainLayout.addComponent(roleLbl, "top:60.0px;left:440.0px;");
// notifyUserLbl
notifyUserLbl = new Label();
notifyUserLbl.setImmediate(false);
notifyUserLbl.setWidth("-1px");
notifyUserLbl.setHeight("-1px");
notifyUserLbl.setValue("Notify User");
mainLayout.addComponent(notifyUserLbl, "top:100.0px;left:440.0px;");
// firstNameTxt
firstNameTxt = new TextField();
firstNameTxt.setImmediate(false);
firstNameTxt.setWidth("-1px");
firstNameTxt.setHeight("-1px");
firstNameTxt.setRequired(true);
firstNameTxt.setSecret(false);
mainLayout.addComponent(firstNameTxt, "top:22.0px;left:140.0px;");
// lastNameTxt
lastNameTxt = new TextField();
lastNameTxt.setImmediate(false);
lastNameTxt.setWidth("-1px");
lastNameTxt.setHeight("-1px");
lastNameTxt.setRequired(true);
lastNameTxt.setSecret(false);
mainLayout.addComponent(lastNameTxt, "top:22.0px;left:563.0px;");
// emailIdTxt
emailIdTxt = new TextField();
emailIdTxt.setImmediate(false);
emailIdTxt.setWidth("-1px");
emailIdTxt.setHeight("-1px");
emailIdTxt.setRequired(true);
emailIdTxt.setSecret(false);
mainLayout.addComponent(emailIdTxt, "top:60.0px;left:143.0px;");
// passwordFieldTxt
passwordFieldTxt = new PasswordField();
passwordFieldTxt.setImmediate(false);
passwordFieldTxt.setWidth("-1px");
passwordFieldTxt.setHeight("-1px");
passwordFieldTxt.setRequired(true);
mainLayout.addComponent(passwordFieldTxt, "top:136.0px;left:143.0px;");
// checkBox_1
checkBox_1 = new CheckBox();
checkBox_1.setCaption("Operator");
checkBox_1.setImmediate(false);
checkBox_1.setWidth("-1px");
checkBox_1.setHeight("-1px");
mainLayout.addComponent(checkBox_1, "top:104.0px;left:563.0px;");
// statusGroup
statusGroup = new OptionGroup();
statusGroup.setImmediate(false);
statusGroup.setWidth("-1px");
statusGroup.setHeight("20px");
statusGroup.setRequired(true);
mainLayout.addComponent(statusGroup, "top:104.0px;left:140.0px;");
// roleComboBox
roleComboBox = new ComboBox();
roleComboBox.setImmediate(false);
roleComboBox.setWidth("138px");
roleComboBox.setHeight("-1px");
roleComboBox.setRequired(true);
for (int i = 0; i < roleCombo.length; i++) {
roleComboBox.addItem(roleCombo); } mainLayout.addComponent(roleComboBox, "top:60.0px;left:562.0px;"); // saveButton saveButton = new Button("Save", new Button.ClickListener() { /** * */ private static final long serialVersionUID = 8034233094433430666L;
// inline click-listener
public void buttonClick(ClickEvent event) {
try{
Users users=new Users();
users.setEmailid((String)emailIdTxt.getValue());
users.setFirstname((String)firstNameTxt.getValue());
users.setLastname((String)lastNameTxt.getValue());
users.setPassword((String)passwordFieldTxt.getValue());
users.setRole((String)roleComboBox.getValue());
users.setCreatedDate(new Date());
getUserService().insertUser(users);
SpringSecurityDemoApp app = (SpringSecurityDemoApp) getApplication();
final Window mainWindow = app.getMainWindow();
Window childWindow=getWindow();
childWindow.getParent().removeWindow(childWindow);
UserComponent um=new UserComponent();
um.refrshTabel();
}
catch(Exception e){
e.printStackTrace();
}
}
});
saveButton.setImmediate(true);
saveButton.setWidth("-1px");
saveButton.setHeight("-1px");
mainLayout.addComponent(saveButton, "top:240.0px;left:560.0px;");
// cancelButton
cancelButton = new Button();
cancelButton.setCaption("Cancel");
cancelButton.setImmediate(true);
cancelButton.setWidth("-1px");
cancelButton.setHeight("-1px");
mainLayout.addComponent(cancelButton, "top:240.0px;left:640.0px;");
return mainLayout;
}
}