在网格(VAADIN14)使用数据提供商时,选择All Un不正常工作
我使用的是Vaadin 14(14.1.17)和具有多选的数据提供商。 当我点击所有按钮时,未在UI中选择行,但在后端(Grid.getSelectedItems()Works)中选择它们。 另外,当我选择一行然后点击“选择全按”按钮时,gred.getSelectedItems保留上一个值,因此它给出了grids.ize() + 1,而不是取消以前选择的先前值。
我的数据提供商和Bean是这样的:
@Entity
@EqualsAndHashCode
@Table(name = "forms", schema = "click", catalog = "")
public class FormEntity {
private long id;
private String userId;
private String requestorType;
private String confirmationPhone;
private Timestamp submittedDate;
private int status;
private Timestamp approvedDate;
private String comments;
private String organization;
private PatientEntity patientEntity;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Basic
@Column(name = "user_id", nullable = true, length = 70)
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Basic
@Column(name = "requestor_type", nullable = false, length = 50)
public String getRequestorType() {
return requestorType;
}
public void setRequestorType(String requestorType) {
this.requestorType = requestorType;
}
@Basic
@Column(name = "confirmation_phone", nullable = true, length = 50)
public String getConfirmationPhone() {
return confirmationPhone;
}
public void setConfirmationPhone(String confirmationPhone) {
this.confirmationPhone = confirmationPhone;
}
@Basic
@Column(name = "submitted_date", nullable = false)
public Timestamp getSubmittedDate() {
return submittedDate;
}
public void setSubmittedDate(Timestamp submittedDate) {
this.submittedDate = submittedDate;
}
@Basic
@Column(name = "status", nullable = false, length = 11)
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Basic
@Column(name = "approved_date", nullable = false)
public Timestamp getApprovedDate() {
return approvedDate;
}
public void setApprovedDate(Timestamp approvedDate) {
this.approvedDate = approvedDate;
}
@Basic
@Column(name = "comments", nullable = true)
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
@Basic
@Column(name = "organization", nullable = true)
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
@ManyToOne
@JoinColumn(name = "patient_id", referencedColumnName = "id", nullable = false)
public PatientEntity getPatientEntity() {
return patientEntity;
}
public void setPatientEntity(PatientEntity patientEntity) {
this.patientEntity = patientEntity;
}
}
private ConfigurableFilterDataProvider<FormEntity, Void, Map<String, Object>> getFilteringDataProvider(OrganizationDto organizationDto) {
DataProvider<FormEntity, Map<String, Object>> dataProvider =
DataProvider.fromFilteringCallbacks(
query -> {
Map.Entry<String, String> sortOrder = null;
List<QuerySortOrder> sortOrderList = query.getSortOrders();
if (!sortOrderList.isEmpty()) {
QuerySortOrder querySortOrder = sortOrderList.get(0);
sortOrder = new AbstractMap.SimpleEntry<>(querySortOrder.getSorted(),
querySortOrder.getDirection().name());
}
Map<String, Object> filter = query.getFilter().orElse(null);
List<FormEntity> rv = null;
rv = registrationService.fetchForms(organizationDto.getIdentifier(), filter, query.getOffset(), query.getLimit(), sortOrder).getContent();
System.out.println("List size:" + rv.size());
return rv.stream();
},
query -> {
Map<String, Object> filter = query.getFilter().orElse(null);
long count = 0;
//The second callback finds out how many items there are in total in the datasource matching with current filters.
count = registrationService.fetchForms(organizationDto.getIdentifier(), filter, 0, 1, null).getTotalElements();
System.out.println("Count:" + count);
return (int) count;
}
);
return dataProvider.withConfigurableFilter();
}
I am using Vaadin 14 (14.1.17) and data provider with multi-select.
When I hit select all button, the rows aren't selected at UI but they are selected at backend(grid.getSelectedItems() works).
In addition, when I select one row and then hit select all button, grid.getSelectedItems holds the previous value, so it gives grids.size() + 1 instead of unselecting the previous value that was selected before.
My data provider and bean are like this:
@Entity
@EqualsAndHashCode
@Table(name = "forms", schema = "click", catalog = "")
public class FormEntity {
private long id;
private String userId;
private String requestorType;
private String confirmationPhone;
private Timestamp submittedDate;
private int status;
private Timestamp approvedDate;
private String comments;
private String organization;
private PatientEntity patientEntity;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Basic
@Column(name = "user_id", nullable = true, length = 70)
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Basic
@Column(name = "requestor_type", nullable = false, length = 50)
public String getRequestorType() {
return requestorType;
}
public void setRequestorType(String requestorType) {
this.requestorType = requestorType;
}
@Basic
@Column(name = "confirmation_phone", nullable = true, length = 50)
public String getConfirmationPhone() {
return confirmationPhone;
}
public void setConfirmationPhone(String confirmationPhone) {
this.confirmationPhone = confirmationPhone;
}
@Basic
@Column(name = "submitted_date", nullable = false)
public Timestamp getSubmittedDate() {
return submittedDate;
}
public void setSubmittedDate(Timestamp submittedDate) {
this.submittedDate = submittedDate;
}
@Basic
@Column(name = "status", nullable = false, length = 11)
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Basic
@Column(name = "approved_date", nullable = false)
public Timestamp getApprovedDate() {
return approvedDate;
}
public void setApprovedDate(Timestamp approvedDate) {
this.approvedDate = approvedDate;
}
@Basic
@Column(name = "comments", nullable = true)
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
@Basic
@Column(name = "organization", nullable = true)
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
@ManyToOne
@JoinColumn(name = "patient_id", referencedColumnName = "id", nullable = false)
public PatientEntity getPatientEntity() {
return patientEntity;
}
public void setPatientEntity(PatientEntity patientEntity) {
this.patientEntity = patientEntity;
}
}
private ConfigurableFilterDataProvider<FormEntity, Void, Map<String, Object>> getFilteringDataProvider(OrganizationDto organizationDto) {
DataProvider<FormEntity, Map<String, Object>> dataProvider =
DataProvider.fromFilteringCallbacks(
query -> {
Map.Entry<String, String> sortOrder = null;
List<QuerySortOrder> sortOrderList = query.getSortOrders();
if (!sortOrderList.isEmpty()) {
QuerySortOrder querySortOrder = sortOrderList.get(0);
sortOrder = new AbstractMap.SimpleEntry<>(querySortOrder.getSorted(),
querySortOrder.getDirection().name());
}
Map<String, Object> filter = query.getFilter().orElse(null);
List<FormEntity> rv = null;
rv = registrationService.fetchForms(organizationDto.getIdentifier(), filter, query.getOffset(), query.getLimit(), sortOrder).getContent();
System.out.println("List size:" + rv.size());
return rv.stream();
},
query -> {
Map<String, Object> filter = query.getFilter().orElse(null);
long count = 0;
//The second callback finds out how many items there are in total in the datasource matching with current filters.
count = registrationService.fetchForms(organizationDto.getIdentifier(), filter, 0, 1, null).getTotalElements();
System.out.println("Count:" + count);
return (int) count;
}
);
return dataProvider.withConfigurableFilter();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎使用Lombok的
@equalsandhashcode
。默认情况下,它生成了使用实体的所有属性的eqauals和hashcode。这与vaadin的数据模型不合适,因为它希望bean不变,即verraigant> verlair
等属性的变化值不应影响beans的身份。您可以解决此1。在Lomboks注释中定义,该注释仅使用ID
或userId
for equals和hashcode。或2。扩展dataprovider
和OverridegetID
方法,因此使用任何一个。Lombok使用的示例
You seem to use
@EqualsAndHashCode
of Lombok. By default it generates eqauals and hashcode that use all the properties of the entity. This does not work with Vaadin's data model, as it expects the beans to be invariant, i.e. changing value of properties likeconfirmationPhone
should not affect the beans identity. You can solve this either 1. defining in Lomboks annotation that uses only theid
oruserId
for the equals and hashcode. Or 2. ExtendDataProvider
and overridegetId
method so that uses either one.Example of Lombok use below