E ai pessoal,
Estou tentando usar o JQGrid com vraptor mas não estou conseguindo, aparece no grid a quantidade de linhas que tenho no banco só que em branco.
Apresenta o seguinte erro:
16:12:15,521 WARN [CommonAnnotationBeanPostProcessor] Invocation of destroy method failed on bean with name ‘entityManagerCreator’: java.lang.IllegalStateException: EntityManager is closed
Segue os códigos:
Meu Dao
public List<Chamado> listaTodos(){
return dao.listaTodos();
}
Minha classe JQgrid
[code]package br.com.xray.helpers;
import java.util.Collection;
import java.util.List;
import br.com.caelum.vraptor.ioc.Component;
import br.com.xray.modelo.Chamado;
@Component
public class JQgrid {
private int page;
private int total;
private int records;
private List rows;
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getRecords() {
return records;
}
public void setRecords(int records) {
this.records = records;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
}
[/code]
JQGridRow
package br.com.xray.helpers;
import java.util.List;
import br.com.caelum.vraptor.ioc.Component;
@Component
public class JQGridRow {
private Long id;
private List<?> cell;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<?> getCell() {
return cell;
}
public void setCell(List<?> cell) {
this.cell = cell;
}
}
Meu Controller
//testes
@Path("/chamados/load-grid")
public void loadGrid(){
JQgrid jqgrid = new JQgrid();
List rows = new ArrayList<JQGridRow>();
List<Chamado> lista = chamadoDao.listaTodos();
for (Chamado c : lista) {
JQGridRow row = new JQGridRow();
row.setId(c.getChamado_id());
List cells = new ArrayList();
cells.add(c.getChamado_id());
System.out.println(cells);
cells.add(c.getSolicitante());
cells.add(c.getEquipamento());
System.out.println(cells);
cells.add(c.getOcorrencia());
System.out.println(cells);
cells.add(c.getPrioridade());
System.out.println(cells);
row.setCell(cells);
rows.add(row);
}
jqgrid.setRows(rows);
jqgrid.setTotal(10);
jqgrid.setPage(1);
jqgrid.setRecords(10);
System.out.println(jqgrid);
result.use(json())
.withoutRoot()
.from(jqgrid)
// .exclude("usuario_logado_id","data")
.include("rows").serialize();
System.out.println(jqgrid);
}
Meu JSP
<script type="text/javascript">
function Busca()
{
$("#grid-user").jqGrid({
url : "../chamados/load-grid",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, //modificado
datatype : "json",
colNames : [ 'Código', 'Solicitante', 'Ocorrência', 'Prioridade', 'Tipo' ],
colModel : [ {
name : 'chamado_id',
index : 'chamado_id',
width : 80,
align : 'center'
},
{
name : 'solicitante_id',
index : 'solicitante_id',
width : 230
},
{
name : 'ocorrencia',
index : 'ocorrencia',
width : 150
},
{
name : 'prioridade',
index : 'prioridade',
width : 100
},
{
name : 'tipo',
index : 'tipo',
width : 80
}
],
rowNum : 10,
pager : '#pager-user',
height : 200,
viewrecords : true,
sortorder : "desc",
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
cell: "",
id: "codigo"
}
});
JQuery(grid-user).jqGrid('navGrid','#pager-user',{edit:false,add:false,del:false});
}
</script>
<input type="button" value="Pesquisar" onclick="Busca()"/>
<table id="grid-user" >
</div>
</table>
<div id="pager-user"></div>