Estou tentando a um tempo e ainda não consegui, queria pegar os dados de um cliente do campo lista ou busca e passar para um formulario para fazer a edição do mesmo, ja pesquisei e nao achei nada. busca.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:import url="/WEB-INF/jsp/header.jsp"/>
<div id="tamanho_lista">
<a class="btn btn-secondary btn-lg" href="${linkTo[ClienteController].form()}">Novo cliente</a>
<table class="table table-hover">
<thead>
<tr>
<th>NOME</th>
<th>CPF</th>
<th>RG</th>
<th>EMAIL</th>
<th>RUA</th>
<th>BAIRRO</th>
<th>CEP</th>
<th>CIDADE</th>
<th>Editar</th>
<th>Excluir</th>
</tr>
</thead>
<tbody>
<c:forEach items="${clienteList}" var="cliente">
<tr>
<td>${cliente.nome}</td>
<td>${cliente.cpf}</td>
<td>${cliente.rg}</td>
<td>${cliente.email}</td>
<td>${cliente.rua}</td>
<td>${cliente.bairro}</td>
<td>${cliente.cep}</td>
<td>${cliente.email}</td>
<td>
<form action="<c:url value='/cliente/form_att'/>" method="post">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="cliente.cpf" value="${cliente.cpf}">
<input type="submit" value="Editar">
</form>
</td>
<td>
<form action="<c:url value='/cliente/remove'/>" method="post">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="cliente.cpf" value="${cliente.cpf}">
<input type="submit" value="Excluir">
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
clientedao
package br.com.wvs.dao;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import br.com.wvs.model.Cliente;
@RequestScoped
public class ClienteDao {
private EntityManager manager;
@Inject
public ClienteDao(EntityManager manager ) {
this.manager = manager;
}
public ClienteDao() {};
public void adiciona (Cliente cliente) {
manager.getTransaction().begin();
manager.persist(cliente);
manager.getTransaction().commit();
}
public List<Cliente> lista(){
TypedQuery<Cliente> query = manager.createQuery("Select r from Cliente r", Cliente.class);
return query.getResultList();
}
public List<Cliente> busca(String nome) {
manager.getTransaction().begin();
CriteriaBuilder criteria = manager.getCriteriaBuilder();
CriteriaQuery<Cliente> query = criteria.createQuery(Cliente.class);
Root<Cliente> root = query.from(Cliente.class);
Path<String> nmPath = root.<String>get("nome");
Predicate nomeIgual = criteria.like(nmPath,"%" + nome + "%");
query.where(nomeIgual);
TypedQuery<Cliente> tQuery = manager.createQuery(query);
manager.getTransaction().commit();
return tQuery.getResultList();
}
public Cliente find(Cliente cliente) {
return manager.find(Cliente.class, cliente.getCpf());
}
public void remove(Cliente cliente) {
manager.getTransaction().begin();
cliente = find(cliente);
manager.remove(cliente);
manager.getTransaction().commit();
}
public void atualiza(Cliente cliente) {
manager.getTransaction().begin();
cliente = find(cliente);
manager.merge(cliente);
manager.flush();
manager.getTransaction().commit();
}
}