0
I am developing an application and 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 Formapayment and send an object of this type to my JSP to link him 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
From what I was able to identify the "problem" is because of the name of my Formapayment class, if I rename the class to Payment works normally.
Does anyone know what happens?
In the JSP that I do this registration I end up doing the registration of three other things. Plus the part of the payment 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">×</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>
This is my Controller:
@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;
}
Note that the Formapagamento is already changed to Paying off and that way it works and the other does not.
My class is 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 + "]";
}
}
You can share your JSP and Formapagamento?
– Daniela Morais
Tells the jsp code that sends the payment details to the controller so we can better check.
– ayowole agbedejobi
I edited and added JSP, Controller and Class.
– DSCM