public void startUpdate() {

    logger.debug("Entering startUpdate method.");

    if (selected == null) {
      String msg = "Unexpected null value detected for selected row.";
      logger.error(msg);
      throw new RuntimeException(msg);
    }

    // Reloading the entity is required to be sure that the value has not changed since it was
    // read in the data table list of values.
    //
    DettaglioFatturazioneService dfs = ServiceFactory.createService("DettaglioFatturazione");
    selected = dfs.retrieveDeep(selected.getId());

    id = selected.getId();
    codiceCondizioniPagamento =
        selected.getCondizioniPagamento() != null
            ? selected.getCondizioniPagamento().getId()
            : null;
    codiceMetodoPagamento =
        selected.getMetodoPagamento() != null ? selected.getMetodoPagamento().getId() : null;
    codiceIndirizzo = selected.getIndirizzo() != null ? selected.getIndirizzo().getId() : null;
    codiceLayoutStampa =
        selected.getLayoutStampa() != null ? selected.getLayoutStampa().getId() : null;
    validoDa = selected.getValidoDa();
    validoA = selected.getValidoA();
  }
  public void loadContatti() {

    if (dettaglioContrattoGenerale.getId() == null) return;

    ContrattoContattoService cs = ServiceFactory.createService("ContrattoContatto");
    listContatti = cs.listByContratto(dettaglioContrattoGenerale.getId());
  }
  public void loadLingue() {

    if (addettoId == null) return;

    LinguaConosciutaService ls = ServiceFactory.createService("LinguaConosciuta");
    listLingue = ls.listByAddetto(addettoId);
  }
  public void startCreate() {

    logger.debug("Entering startCreate() method.");

    id = null;
    selectedContatto = null;
    validoDa = null;
    validoA = null;

    // Load list of available contatti records.
    //
    ContattoService cs = ServiceFactory.createService("Contatto");
    listContattiDisponibili = cs.listDisponibiliPerContratto(dettaglioContrattoGenerale.getId());
  }
  public void startUpdate() {

    logger.debug("Entering startUpdate() method.");

    // Reloading the entity is required to be sure that the value has not changed since it was
    // read in the data table list of values.
    //
    ContrattoContattoService ccs = ServiceFactory.createService("ContrattoContatto");
    selected = ccs.retrieveDeep(selected.getId());

    id = selected.getId();

    selectedContatto = selected.getContatto();
    validoDa = selected.getValidoDa();
    validoA = selected.getValidoA();

    // Load list of available contatti records.
    //
    ContattoService cs = ServiceFactory.createService("Contatto");
    listContattiDisponibili =
        cs.listDisponibiliPerContratto(
            dettaglioContrattoGenerale.getId(), selectedContatto.getId());
  }
  @PostConstruct
  public void init() {

    LUTService lutService = ServiceFactory.createService("LUT");

    // Load condizioni pagamento LUT.
    //
    listCondizioniPagamento = lutService.listItems("CondizioniPagamento");

    // Load metodo pagamento LUT.
    //
    listMetodoPagamento = lutService.listItems("MetodoPagamento");

    // Load layout stampa LUT.
    //
    listLayoutStampa = lutService.listItems("LayoutStampa");

    // Load available indirizzi.
    //
    ContrattoService cs = ServiceFactory.createService("Contratto");
    listIndirizzo = cs.listAvailableIndirizzi(dettaglioContrattoGenerale.getId());

    logger.debug("Initialization performed.");
  }
  public void startUpdate() {

    logger.debug("Entering startUpdate() method.");

    // Reloading the entity is required to be sure that the value has not changed since it was
    // read in the data table list of values.
    //
    LinguaConosciutaService ls = ServiceFactory.createService("LinguaConosciuta");
    selected = ls.retrieveDeep(selected.getId());

    id = selected.getId();
    codiceLingua = selected.getLingua() != null ? selected.getLingua().getId() : null;
    codiceLivelloLingua =
        selected.getLivelloLingua() != null ? selected.getLivelloLingua().getId() : null;
    note = selected.getNote();
  }
  @PostConstruct
  public void init() {

    LUTService lutService = ServiceFactory.createService("LUT");

    // Load lingua LUT.
    //
    listLingua = lutService.listItems("Lingua");

    // Load livello lingua LUT.
    //
    listLivelloLingua = lutService.listItems("LivelloLingua");

    // Load list for data table.
    //
    loadLingue();

    logger.debug("Initialization performed.");
  }
  public void doDelete() {

    if (selected == null || selected.getId() == null) {
      String msg = "Unexpected null id detected.";
      logger.error(msg);
      throw new RuntimeException(msg);
    }

    // Delete the entity.
    //
    try {
      DettaglioFatturazioneService dfs = ServiceFactory.createService("DettaglioFatturazione");
      dfs.delete(selected.getId());

      logger.debug("Entity successfully deleted.");

      // Add a message.
      //
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_INFO,
              "Record eliminato",
              "L'eliminazione del dettaglio di fatturazione si è conclusa con successo.");
      FacesContext.getCurrentInstance().addMessage(null, message);

      // Signal to modal dialog that everything went fine.
      //
      RequestContext.getCurrentInstance().addCallbackParam("ok", true);

    } catch (Exception e) {

      logger.warn("Exception caught while deleting entity.", e);

      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Errore di sistema",
              "Si è verificato un errore in fase di eliminazione del record.");
      FacesContext.getCurrentInstance().addMessage(null, message);
    }
  }
  public void doDelete() {

    // Create service to delete record.
    //
    LinguaConosciutaService ls = ServiceFactory.createService("LinguaConosciuta");

    try {
      ls.delete(selected.getId());

      // Everything went fine.
      //
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_INFO,
              "Successo",
              "L'eliminazione del record selezionato si è conclusa con successo.");
      FacesContext.getCurrentInstance().addMessage(null, message);

      // Reset selection.
      //
      selected = null;

      // Refresh list.
      //
      loadLingue();

    } catch (Exception e) {

      logger.warn("Exception caught while deleting entity.", e);

      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Errore di sistema",
              "Si è verificato un errore in fase di eliminazione del record.");
      FacesContext.getCurrentInstance().addMessage(null, message);
    }
  }
  public void doSave() {

    // Save the entity.
    //
    try {
      DettaglioFatturazioneService dfs = ServiceFactory.createService("DettaglioFatturazione");

      if (id == null) {
        dfs.create(
            dettaglioContrattoGenerale.getId(),
            codiceCondizioniPagamento,
            codiceMetodoPagamento,
            codiceIndirizzo,
            codiceLayoutStampa,
            validoDa,
            validoA);
        logger.debug("Entity successfully created.");

        // Add a message.
        //
        FacesMessage message =
            new FacesMessage(
                FacesMessage.SEVERITY_INFO,
                "Record creato",
                "La creazione del nuovo dettaglio di fatturazione si è conclusa con successo.");
        FacesContext.getCurrentInstance().addMessage(null, message);

      } else {

        dfs.update(
            id,
            codiceCondizioniPagamento,
            codiceMetodoPagamento,
            codiceIndirizzo,
            codiceLayoutStampa,
            validoDa,
            validoA);
        logger.debug("Entity successfully updated.");

        // Add a message.
        //
        FacesMessage message =
            new FacesMessage(
                FacesMessage.SEVERITY_INFO,
                "Record aggiornato",
                "La modifica del dettaglio di fatturazione si è conclusa con successo.");
        FacesContext.getCurrentInstance().addMessage(null, message);
      }

      // Signal to modal dialog that everything went fine.
      //
      RequestContext.getCurrentInstance().addCallbackParam("ok", true);

    } catch (Exception e) {

      logger.warn("Exception caught while saving entity.", e);

      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Errore di sistema",
              "Si è verificato un errore in fase di salvataggio del record.");
      FacesContext.getCurrentInstance().addMessage(null, message);
    }
  }
  public void doSave() {

    // Apply form-level validations.
    //
    if (!formValidations()) return;

    // Create service to persist data.
    //
    LinguaConosciutaService ls = ServiceFactory.createService("LinguaConosciuta");

    try {
      LinguaConosciuta entity = null;

      // If the record already exists, just update it.
      //
      if (id != null) {

        entity = ls.update(id, codiceLingua, codiceLivelloLingua, note);

        logger.debug("Entity successfully updated.");
      }

      // Otherwise create a new record.
      //
      else {

        entity = ls.create(addettoId, codiceLingua, codiceLivelloLingua, note);
        id = entity.getId();

        logger.debug("Entity successfully created.");
      }

      // Everything went fine.
      //
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_INFO,
              "Successo",
              "Il salvataggio dei dati si è concluso con successo.");
      FacesContext.getCurrentInstance().addMessage(null, message);

      // Refresh list.
      //
      loadLingue();

      // Signal to modal dialog that everything went fine.
      //
      RequestContext.getCurrentInstance().addCallbackParam("ok", true);

    } catch (Exception e) {

      logger.warn("Exception caught while saving entity.", e);

      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Errore di sistema",
              "Si è verificato un errore in fase di salvataggio del record.");
      FacesContext.getCurrentInstance().addMessage(null, message);
    }
  }