java - How to Populate a jeasyui DataGrid with Spring Controller -
i'm not achieving mimetize this tutorial using spring mvc controller.
datagrid not populating rows java/spring controller data retrieved. i'm not reproducing entyre jsp code quite similar example above.
the spring "controlteste" follows responsible retrieving data db, build json string (using gson) , sending response. in tutorial, task done php (directly view, without "controller" layer).
@requestmapping(value = "/controlteste", method = requestmethod.get) public @responsebody string teste(status status, httpsession httpsession) { gson gson = new gsonbuilder().setdateformat("dd-mm-yyyy").setprettyprinting().create(); session sess = (session) httpsession.getattribute("hibsess"); statusdao stadao = new statusdao(sess); list<status> lista = stadao.findall(); string gstatus = new string(); try{ gstatus = gson.tojson(lista); system.out.println(gstatus); } catch(exception e){ e.printstacktrace(); } return gstatus; }
the json generated is:
{ "id": 2, "descricao": "novo status", "sigla": "sta", "estadofinal": true, "erro": true }
and datagrid's config (in jsp) is:
<script type="text/javascript"> $('#dg').edatagrid({ url: 'controlteste', saveurl: 'statuscreate', updateurl: 'statusupdate', destroyurl: 'statusdelete' }); <table id="dg" title="cadastro de status" class="easyui-datagrid" style="width: 700px; height: 250px" url="controlteste" toolbar="#toolbar" pagination="true" rownumbers="true" fitcolumns="true" singleselect="true"> <thead> <tr> <th field="id" width="20">id</th> <th field="sigla" width="40">sigla</th> <th field="descricao" width="50">descrição</th> <th field="erro" width="30">erro?</th> <th field="estadofinal" width="30">estado final?</th> </tr> </thead> </table> <div id="toolbar"> <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="novo()">novo</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editar()">editar</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="remover()">remover</a> </div>
right i'm interested in "controlteste" controller, due responsible retrieving data populate datagrid.
thanks helping!
responding question, usefull sb someday:
@requestmapping(value = "/statuslista") public @responsebody string teste(status status, httpsession httpsession, httpservletrequest req, httpservletresponse res) throws ioexception { session sess = (session) httpsession.getattribute("hibsess"); statusdao stadao = new statusdao(sess); list<status> lista = stadao.findall(); gson gson = new gsonbuilder().setdateformat("dd-mm-yyyy").setprettyprinting().create(); string gliststatus = gson.tojson(lista); return gliststatus; }
i've done changings in controller method (and i've changed name too).
Comments
Post a Comment