public SelectItem[] getDriverAllOptions() { List<Driver> drivers = dm.getAllDrivers(); SelectItem[] items = new SelectItem[drivers.size() + 1]; items[0] = new SelectItem(""); int i = 1; for (Driver d : drivers) { items[i++] = new SelectItem(d.getId().toString(), d.toString()); } return items; }
// HELPERS public SelectItem[] getDriverOptions() { List<Driver> drivers = dm.getFreeDrivers(); List<Driver> freeDrivers = new ArrayList<Driver>(); if (historiesForDate.isEmpty()) { SelectItem[] items = new SelectItem[drivers.size()]; int i = 0; for (Driver d : drivers) { items[i++] = new SelectItem(d.getId().toString(), d.toString()); } return items; } else { boolean isFree = true; for (Driver d : drivers) { for (History his : historiesForDate) { if (d.getId().equals(his.getDriver().getId())) { isFree = false; break; } } if (isFree) { freeDrivers.add(d); } else isFree = true; } SelectItem[] items = new SelectItem[freeDrivers.size()]; int i = 0; for (Driver d : freeDrivers) { items[i++] = new SelectItem(d.getId().toString(), d.toString()); } return items; } }