I am new to Web development, primefaces and stackoverflow.
I am not even sure if I am allowed to ask generic questions like this here, but I thought I give it a shot since it is driving me crazy!!
So I am using Primefaces schedule component to develop a scheduler. This scheduler reads events for each day from a database, and displays it on the scheduler. of course users are able to add/edit/delete these events by clicking on the date and a dialog opens and user manipulates the data.
It’s a shift scheduler, so the number of shifts per day is limited and consistent (and mandatory). For example, everyday has a
1) moderator (MM)
2) morning security guard (MSG)
3) afternoon security guard (ASG)
4) overnight security guard (NSG)
it’s only a matter of who takes these shifts, otherwise these shifts must be filled in 2 days in advance. So what I would like to do is
1) read data from DB and populate the day with those that are already assigned (easy)
2) if they are not assigned yet, show an empty field (not from database anymore, a view only event)
such as
Wednesday Thursday Friday
MM bob MM mike MM <empty>
MSG mike MSG john MSG <empty>
ASG john ASG <empty> ASG <empty>
NSG dave NSG bob NSG <empty>
here, all those that are assigned already are read from the database, but I have no idea how to display those that are not yet assigned. Note that they are not in the database, they are just in the view until a user clicks on it to assign it to himself.
Any suggestion, peace of code, or any other help would be very much appreciated. Even if you know a better choice (than primefaces), feel free to let me know.
My suggestion would be to retrieve the values from database and loop them. When you should have a value for a specific date, and you don’t (because not in database) then add an empty one (to the variable in your bean)
Or you could instantiate a whole list of empty entries in your bean (constructor) and when retrieving results from database, loop them and add then (replace the empty one) to you bean variable. That way you end up with a list of empty and filled in spots.
How do you read in these values from database? Is it a list?