0
Hello guys I have the following error when I try to delete something from my table
WARNING: Failed to bind request element: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: ""
I have a button that should pass the id of the selected line to the value of the Hidden field in the modal to confirm the deletion follows below:
<table class="table">
<tr>
<th>Nome</th>
<th>Endereço</th>
<th>Vagas</th>
<th>Preço</th>
</tr>
<c:forEach items="${estacionamentos }" var="e">
<tr>
<td>${e.nome }</td>
<td>${e.endereco }</td>
<td>${e.vagas }</td>
<td>${e.preco }</td>
<td>
<c:url value="/estacionamento/editar/${e.codigo }" var="link"/>
<a href="${link}" class="btn btn-primary btn-sm">Editar</a>
<button onclick="codigo.value = ${e.codigo}" type="button"
class="btn btn-danger btn-sm" data-toggle="modal" data-target="#excluirModal">
Excluir
</button>
</td>
</tr>
</c:forEach>
</table>
modal:
<!-- Modal -->
<div class="modal fade" id="excluirModal" 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">Confirmação</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Realmente deseja excluir o estacionamento?
</div>
<div class="modal-footer">
<c:url value="/estacionamento/excluir/" var="action"/>
<form action="${action }" method="post">
<input type="hidden" name="codigo" id="codigo">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Excluir</button>
</form>
</div>
</div>
</div>
</div>
When instead of Hidden I use a text or number field and pass an id manually the deletion occurs normally, I wonder if I’m using the onclick event in the correct way or if it’s another mistake I’m making.