public void updateDialog() {
    Map<String, String> requestParams =
        FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    if (!requestParams.containsKey("id")) {
      return;
    }
    int id = Integer.valueOf(requestParams.get("id"));

    dialogPerformance = UFOService.getInstance().getPerformanceById(id);
  }
  @PostConstruct
  public void init() {
    // load dates
    List<XMLGregorianCalendar> gregDates =
        UFOService.getInstance().getDatesWithPerformances().getDateTime();
    for (XMLGregorianCalendar d : gregDates) {
      if (d.getYear() >= Calendar.getInstance().get(Calendar.YEAR)) {
        dates.add(d.toGregorianCalendar().getTime());
      }
    }

    // times to display
    times = new ArrayList<>();
    for (int t = 14; t <= 23; ++t) {
      times.add(t % 24);
    }

    // artists / venues / performances
    reload();

    // category / country
    categories = UFOService.getInstance().getAllCategories().getCategory();
    countries = UFOService.getInstance().getAllCountries().getCountry();
  }
  private void reload() {
    UltimateFestivalOrganizerSoap ufo = UFOService.getInstance();

    venues = ufo.getAllVenues().getVenue();
    artists = ufo.getAllButDeletedArtists().getArtist();

    // Performances
    performances.clear();

    if (performancesSessionBean.getSelectedDate() == null) {
      return;
    }

    // fill with new
    for (Venue v : venues) {
      performances.put(v.getId(), new HashMap<>());

      for (int hour = 14; hour <= 23; ++hour) {
        Performance p = new Performance();
        p.setVenue(v);

        Calendar c = new GregorianCalendar();
        c.setTime(performancesSessionBean.getSelectedDate());
        c.add(Calendar.HOUR_OF_DAY, hour);
        p.setDateTime(dateToGregorian(c.getTime()));

        Artist a = new Artist();
        a.setId(0);
        p.setArtist(a);

        performances.get(v.getId()).put(hour, p);
      }
    }

    // fill with existing
    List<Performance> allPerformances =
        ufo.getPerformancesByDate(dateToGregorian(performancesSessionBean.getSelectedDate()))
            .getPerformance();
    for (Performance p : allPerformances) {
      int venueId = p.getVenue().getId();
      int hour = p.getDateTime().getHour();

      performances.get(venueId).put(hour, p);
    }
  }
  public void onSelectedArtistChange(int viewId, int time) {
    // check login
    if (!userBean.getLoggedIn()) {
      return;
    }

    // execute action
    Performance p = performances.get(viewId).get(time);

    UltimateFestivalOrganizerSoap ufo = UFOService.getInstance();

    if (p.getId() == 0 && p.getArtist().getId() == 0) {
      return;
    }

    // send to server
    boolean success = true;
    if (p.getId() == 0 && p.getArtist().getId() != 0) {
      success = ufo.addPerformance(p);
    } else if (p.getId() != 0 && p.getArtist().getId() == 0) {
      ufo.deletePerformance(p);
      success = true;
    } else if (p.getId() != 0 && p.getArtist().getId() != 0) {
      success = ufo.updatePerformance(p);
    }

    // message
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FacesMessage facesMessage;
    if (success) {
      facesMessage =
          new FacesMessage(FacesMessage.SEVERITY_INFO, "Saved", "Data was saved on the server.");
    } else {
      facesMessage =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Error",
              "The selected artist was invalid. The item will be reset.");
      reload();
    }
    facesContext.addMessage(null, facesMessage);
  }