public SelectItem[] getRouteOptions() { List<Route> routes = rm.getAllRoutes(); List<Route> freeRoutes = new ArrayList<Route>(); if (historiesForDate.isEmpty()) { SelectItem[] items = new SelectItem[routes.size()]; int i = 0; for (Route r : routes) { items[i++] = new SelectItem(r.getId().toString(), r.toString()); } return items; } else { boolean isFree = true; for (Route r : routes) { for (History his : historiesForDate) { if (r.getId().equals(his.getRoute().getId())) { isFree = false; break; } } if (isFree) { freeRoutes.add(r); } else isFree = true; } SelectItem[] items = new SelectItem[freeRoutes.size()]; int i = 0; for (Route r : freeRoutes) { items[i++] = new SelectItem(r.getId().toString(), r.toString()); } return items; } }
public SelectItem[] getRouteAllOptions() { List<Route> routes = rm.getAllRoutes(); SelectItem[] items = new SelectItem[routes.size() + 1]; items[0] = new SelectItem(""); int i = 1; for (Route r : routes) { items[i++] = new SelectItem(r.getId().toString(), r.toString()); } return items; }
public String addHistory() { history.setDriver(dm.getDriver(driverId)); history.setBus(bm.getBus(busId)); history.setRoute(rm.getRoute(routeId)); history.setDate(date); hm.addHistory(history); history = new History(); driverId = 0L; busId = 0L; routeId = 0L; historiesForDate = hm.getHistoryByDate(date); return "showLines?faces-redirect=true"; }