I’m having a problem when and I add some items that already contains other list. I’d say Grid is traying to show all the data creating new rows (empty) but with the same PK.
- Are you sure the
equals
andhashCode
methods of your item class are implemented properly? - Could you show us how you set up your grid and how you set the items?
Honestly I didn’t implemented equals or hashCode, but my problem has relation with “son” list not with the current one.
Do you think it could be related?, I have implemented other Grids with “easier” classes and I didn’t have this problem.
BookDay is the List that is showed wrongly to the grid
I dont know what BookDay is. and honestly, I don’t understand completely what you mean with when and I add some items that already contains other list.
I’m not going to assume or think anything before I can see your actual implementation.
@Entity
@Table(name = "booking")
public class Booking {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
private Employee bookedBy;
private String reason = "";
private LocalDateTime firstDay;
private LocalDateTime lastDay;
@ManyToOne
private Room room;
@OneToMany(fetch = FetchType.EAGER)
private List<BookDay> bookDays = new ArrayList<BookDay>();
public class BookingGrid extends Grid<Booking>{
/**
*
*/
private static final long serialVersionUID = -6303470678550544041L;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
public BookingGrid() {
super(Booking.class);
createGrid();
}
private void createGrid() {
removeAllColumns();
addComponentColumn(item -> getBookedBy(item)).setHeader("Reservado por");
addColumn("reason").setHeader("Proyecto");
addComponentColumn(item -> getStartDate(item)).setHeader("Desde");
addComponentColumn(item -> getEndDate(item)).setHeader("Hasta");
setSelectionMode(SelectionMode.NONE);
}
Sorry, I just saw my error, I tried to attach a piece of code.
For each object inside the son list(bookDay) a new row empty is created in the Grid.
This grid should be showing just Booking
Okay, but can you show the code where you call grid.setItems(..)
or grid.setDataProvider(..)
@Override
public void setParameter(BeforeEvent event, Integer parameter) {
Optional<Room> optionalRoom = roomService.findById(parameter);
if (parameter == null || !optionalRoom.isPresent()) {
event.forwardTo(RoomSearchView.class);
} else {
this.currentRoom = optionalRoom.get();
nameTextField.setValue(currentRoom.getName());
floorTextField.setValue(currentRoom.getFloor());
phoneTextField.setValue(currentRoom.getPhone());
name.setText("Sala " + currentRoom.getName());
grid.setItems(currentRoom.getBookings());
}
}
Yes, of course, in this case I didn’t use a data provider.
Here are your next steps:
- implement
equals
andhashCode
methods on your Booking class. Check if this solved it - look for other calls of
grid.setItems(..)
orgrid.setDataProvider(..)
- Debug the returned list of
currentRoom.getBookings()
and check if this list is correct
You were right, I never saw that before but it’s a problem with my jpa implementation.
Thanks a lot I’m sorry for the inconveniences.