Object Linking

0

I'm developing an application and I came across the following "problem":

@RequestMapping("/pagamentos")
public ModelAndView pagamentos(FormaPagamento pagamento){       
    ModelAndView model = new ModelAndView("cadastro-pagametos");        
    return model;
}

I have a class called FormPay and send an object of this type to my JSP to link it to my registration form. However, the following error is reported:

java.lang.IllegalStateException: 
Neither BindingResult nor plain target object 
for bean name 'pagamento' available as request attribute

So I was able to identify the "problem" is because of the name of my FormPayment class, if I rename the class for Payment it works normally.

Does anyone know why this happens?

In the JSP that makes this register I end up doing the registration of 3 other things. But the payment part is this:

My MODAL with the registration form:

 <!-- MODAL DE CADASTRO DE FORMAS DE PAGAMENTO -->
<div class="modal fade" id="pagamento" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">PAGAMENTO</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <form:form id="formFormaPagamento" action="${s:mvcUrl('CC#cadastroPagamentos').build()}" method="POST" commandName="pagamento">
          <div class="container-fluid">
                <div class="card">
                    <div class="card-body">                                                         
                        <form:input cssClass="form-control" name="id" path="id" id="id" type="hidden" readonly="true"/>
                        <h5>Forma de Pagamento:</h5>
                        <div class="input-group input-group-lg">
                            <form:input type="text" cssClass="form-control" id="nome" name="nome" path="nome"/>
                        </div>  
                        <br>          
                        <div class="botao">                                         
                            <button type="submit" class="btn btn-success btn-lg"><i class="far fa-save"></i> SALVAR</button>                
                        </div>                      
                    </div>
                </div>
            </div>

          </form:form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>

My Controller is this:

    @RequestMapping("/cadastros")
    public ModelAndView cadastros(Marca marca, Categoria categoria, Motivo motivo, Pagamento pagamento) {
       ModelAndView model = new ModelAndView("tela-cadastros");     
       model.addObject("marcas", marcaDAO.lista());
       model.addObject("categorias", categoriaDAO.lista());
       model.addObject("pagamentos", pagamentoDAO.lista());
       model.addObject("descartes", motivoDAO.lista());
       return model;
}

Notice that PaymentStart is already changed to Payment , so it works and the other does not.

My class looks like this:

  @Entity
  @Table(name="mejt_tbl_cad_pagamentos")
  public class Pagamento {
      @Id
      @GeneratedValue
      private int id;
      @Column(length=15,nullable=false)
      private String nome;

      public Pagamento() {}

      public Pagamento(int id, String nome) {
         this.id = id;
         this.nome = nome;
      }

      public int getId() {
         return id;
      }

      public void setId(int id) {
         this.id = id;
      }

      public String getNome() {
         return nome;
      }

      public void setNome(String nome) {
        this.nome = nome;
      } 

      @Override
      public String toString() {
        return "FormaPagamento [id=" + id + ", nome=" + nome + "]";
      }
  }
    
asked by anonymous 20.12.2018 / 11:41

0 answers