我正在尝试创建一个带有嵌套属性的网格。但我找不到在网格列中显示嵌套属性字段的方法。
private Component buildGrid() {
branchGrid = new Grid<>(Branch.class);
branchGrid.setItems(DummyData.allBranches);
branchGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
branchGrid.setSizeFull();
branchGrid.getEditor().setEnabled(false);
branchGrid.addComponentColumn((ValueProvider<Branch, Component>) branch -> {
Button btnEdit = new Button(VaadinIcons.EDIT);
btnEdit.addStyleName(MaterialTheme.BUTTON_CUSTOM + " " + MaterialTheme.BUTTON_BORDER);
btnEdit.setDescription("Click for edit!");
return btnEdit;
}).setId("edit");
branchGrid.setColumnOrder("edit", "branchId", "branchName", "email", "phone", "location", "owner", "active");
return branchGrid;
}
public class Branch {
private String branchId; //yymmddHHmmSSS
private String branchName;
private String email;
private String phone;
private String location;
private User owner;
private boolean active;
}
public class User {
private long userId;
private String username;
private String password;
private String email;
}
我只想在网格中显示 user.username。但在此代码中,显示所有用户对象堆栈引用或其他。
像这样:com.meyrasoft.checkupbox.model.User@12703bc