i have to get a datatable in JSF Primefaces Java filled with data that comes from the db and if there's not enough data, i have to fill it with empty or new objects/rows.
So to clear this above a bit, every row in the datatable represents a day in the present month. The data that's already in the db is data per date in that month.
So if i have only data for the second day of june. I need in my datatable an new empty object on the first day of the month, on the second day there has to be the data from the db.
So i've tried to do that but my result is the data from the db comes in the datatable stackt above the datatable. From there on it begins again from the first of the month.
So i want to set the database data on the specific day of the month.
Here is my code:
LocalDate date = LocalDate.now().withDayOfMonth(1);
dayDataList = dayDataTaskService.findAllDataForUser("Wim",Date.valueOf(date));
LocalDate end = date.plusMonths(1);
if (dayDataList == null || dayDataList.isEmpty()) {
List<DayData> dayDataList = new ArrayList<>();
while (date.isBefore(end)) {
DayData dat = new DayData();
dat.setRamDate(Date.valueOf(date));
dayDataList.add(dat);
date = date.plusDays(1);
}
} else {
while (date.isBefore(end)) {
int day = date.getDayOfMonth();
if(dayDataList.contains(Date.valueOf(date)))
{
for(DayData d : dayDataList)
{
if(d.getRamDate().equals(Date.valueOf(date)))
{
System.out.println(date + "-" + d.getRamDate());
dayDataList.set(5,d);
date.plusDays(1);
}
}
}else{
dayDataList.add(new DayData(Date.valueOf(date)));
date = date.plusDays(1);
}
and my result is:
So you can see that the first record is the first of the month and is data from the db. The second record is also the first of the month with no data. So i need to replace the rows in the datatable with these that are in the db at the specific date in the datatable