public void selecionarFunc() {
   try {
     this.funcionario = service.findById(getFuncionarioSel().getFunId());
   } catch (ApplicationMessageException e) {
     FacesUtils.error(e.getMessage());
   }
   FacesUtils.clearForm();
 }
  public void delete() {
    try {
      this.service.delete(this.funcionario);
      this.init();

    } catch (BusinessMessageException e) {
      FacesUtils.info(e.getMessage());
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }
  }
  public void save() {
    try {
      this.funcionario.setNome(this.funcionario.getNome());
      this.service.save(this.funcionario);
      this.init();

      FacesUtils.infoI18n("app.generic.successSave");
    } catch (BusinessMessageException e) {
      FacesUtils.info(e.getMessage());
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }
  }
  public List<Accesslist> getAccesslists() {
    try {
      accesslists = serviceAccess.findAll();
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }

    return accesslists;
  }
  public List<Funcionario> getFuncionariosCmb() {
    try {
      funcionariosCmb = service.findAll();
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }

    return funcionariosCmb;
  }
  public void saveSenha() {
    try {
      Integer idFun = serviceSession.getFuncionarioIdSession();

      try {
        Funcionario oldFunc = service.findById(idFun);

        if (!SecurityUtils.md5(this.funcionarioSenha.getSenha()).equals(oldFunc.getSenha())) {
          FacesUtils.errorI18n("app.entity.funcionario.error.invalidPassword");
          return;
        }

        if (!this.funcionarioSenha
            .getValidNovaSenha()
            .equals(this.funcionarioSenha.getNovaSenha())) {
          FacesUtils.errorI18n("app.entity.funcionario.error.invalidNewPassword");
          return;
        }

      } catch (ApplicationMessageException e) {
        FacesUtils.error(e.getMessage());
      }

      this.service.save(this.funcionarioSenha);
      this.init();

      FacesUtils.infoI18n("app.generic.successSave");
    } catch (BusinessMessageException e) {
      FacesUtils.info(e.getMessage());
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }
  }
  /** ************************************************************ */
  public List<Funcionario> search() {
    try {
      Funcionario searchFunc = new Funcionario();

      searchFunc.setNome(this.funcionarioSearch.getNome());
      searchFunc.setAtivo(this.funcionarioSearch.getAtivo());

      this.funcionarios = service.find(searchFunc);
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }
    return this.funcionarios;
  }
  public List<String> searchNome(String query) {
    List<String> suggestions = new ArrayList<String>();

    try {
      List<Funcionario> funcionarios = this.service.findListByNome(query);

      if (funcionarios != null) {
        for (Funcionario funcionario : funcionarios) {
          suggestions.add(funcionario.getNome());
        }
      }

    } catch (Exception e) {
      FacesUtils.error(e.getMessage());
    }

    return suggestions;
  }
  @PostConstruct
  public void init() {
    this.funcionarioSearch = new FuncionarioDTO();
    this.funcionario = new Funcionario();
    this.funcionarios = this.search();
    this.funcionarioSel = new Funcionario();
    this.disableDepartamento = true;
    this.disableDepartamentoSearch = true;
    this.disableSite = true;
    this.numSeq = 1;

    Integer idFun = serviceSession.getFuncionarioIdSession();

    try {
      this.funcionarioSenha = service.findById(idFun);
    } catch (ApplicationMessageException e) {
      FacesUtils.error(e.getMessage());
    }
  }
 public void insert() {
   this.funcionario = new Funcionario();
   this.funcionarioSel = new Funcionario();
   this.numSeq = 1;
   FacesUtils.clearForm();
 }