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 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();
  }