Differentiate itensv

Asked

Viewed 16 times

1

I have two classes being registered, the Meals and Food class. They perform several registrations at the same time, but I’m not able to differentiate the items for each meal. I select the meal and its respective foods when selecting a new meal and other foods, when I register the data are becoming incoherent, because it registers all food within the same meal and the next meal it registers the same items.

String diasRefeicao[] = request.getParameterValues("diarefeicao");
String idTipoRefeicao[] = request.getParameterValues("idtiporefeicao");

Cardapio cardapio = new Cardapio();
cardapio.setIdCardapio(idCardapio);

String alimentos[] = request.getParameterValues("idalimento");
String quantidades[] = request.getParameterValues("quantidadealimentorefeicao");
String medidaalimento[] = request.getParameterValues("tipomedidaalimentorefeicao");

Integer idRefeicao = null;


try {
    for (int ii = 0; ii < idTipoRefeicao.length; ii++){
        TipoRefeicao tipoRefeicao = new TipoRefeicao();
        tipoRefeicao.setIdTipoRefeicao(Integer.parseInt(idTipoRefeicao[ii]));

        Refeicao refeicao = new Refeicao();
        refeicao.setDiaRefeicao(diasRefeicao[ii].toUpperCase().trim());
        refeicao.setStatusRefeicao("A");
        refeicao.setSincronizaRefeicao(1);
        refeicao.setTipoRefeicao(tipoRefeicao);
        refeicao.setCardapio(cardapio);

        RefeicaoDAOImpl daorefeicao = new RefeicaoDAOImpl();
        idRefeicao = daorefeicao.cadastrar(refeicao);

        if (idRefeicao != null) {
            refeicao.setIdRefeicao(idRefeicao);
            for (int i = 0; i < alimentos.length; i++) {
                AlimentoRefeicao alimentoRefeicao = new AlimentoRefeicao();
                Alimento alimento = new Alimento();

                alimento.setIdAlimento(Integer.parseInt(alimentos[i]));
                alimentoRefeicao.setAlimento(alimento);
                alimentoRefeicao.setRefeicao(refeicao);
                alimentoRefeicao.setTipoMedidaAlimentoRefeicao(medidaalimento[i]);
                alimentoRefeicao.setQuantidadeAlimentoRefeicao(Double.parseDouble(quantidades[i]));
                alimentoRefeicao.setSincronizaAlimentoRefeicao(1);
                try{
                    GenericDAO dao = new AlimentoRefeicaoDAOImpl();
                if (dao.cadastrar(alimentoRefeicao)) {
                    mensagem = "Cadastrado com sucessso ";
                } else {
                    mensagem = "Erro ao cadastrar itens da refeição";
                }
                } catch (Exception ex) {
                    System.out.println("Erro ao cadastrar itens da refeição" + ex.getMessage());
                    ex.printStackTrace();
                }
            }
  • A meal is not referenced to a glutton? : ) Other than what/who it is referenced to?

  • The meal is linked to the menu in which it is linked to the patient

  • I was having a problem on the other topic no one helped me. Then I managed to solve with the help of another forum, I changed the question because I had no answer. They came and said I couldn’t do it. So I created another topic. But OK I wait for the other forum to answer me. Vlw

  • Leticia you twisted what you said here. I merely warned you about this practice, which was not recommended, but I also pointed out that as the question still had no answers, even though there were comments, there would be no major problems. If this question is of another problem, it will not be closed as duplicate, but it would be interesting to post the solution you thought of the other as the answer there, to show that they are different problems.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.