cancel
Showing results for 
Search instead for 
Did you mean: 

extjs grid + json+ webscript

marcuzzo86
Champ in-the-making
Champ in-the-making
hi guys i have a question for you.
i'm trying to retrieve data from alfresco via webscript and then put it in a ExtJS grid.
my webscript work fine, these are :
- descriptor file:
<webscript>
  <shortname>prova</shortname>
  <description>Lists all documents with type: FATTURA ATTIVA</description>
  <url>/marco/search</url>
  <format default="json">extension</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

- free marker template file:
{
   total: ${total},
   rows: [
   <#list nodes as document>
           {"id": "${document.nodeRef}", "name": "${document.name}"}
   </#list>
   ]
}

-and javascript file:
var type='TYPE:"{http://www.marco.com/model/content/1.0}fatt_a"';
nodes = search.luceneSearch(type);

var start = 0;
var limit = 100;

if (args.start != undefined) {
   start = args.start;
}

if (args.limit != undefined) {
   limit = args.limit;
}

pagedResults = new Array();
for (i=0; i < nodes.length && i < limit; i++ ) {
   var node = nodes[(+start + i)];
   if (node != undefined) {
      pagedResults.push(node);
   }
}

model.nodes = pagedResults;
model.total = nodes.length;

how can you see it is a very simple webscript that return a list of document.
the view files are these:

-the javascript file that ask alfresco and then create the grid:

Ext.onReady(function() {
var record = Ext.data.Record.create([ //definisco la forma del record
    {id: 'id', name: 'name'},                 
]);

var myReader = new Ext.data.JsonReader({
    totalProperty: "total",             // numero righe
    root: "rows",                         // lista dei dati da esporre (label del file json)
}, record);

   var grid = new Ext.grid.GridPanel({
      store: new Ext.data.Store({
                 // load using HTTP
            proxy: new Ext.data.HttpProxy({url: 'http://localhost:8080/alfresco/service/opsoro/search'}), //effettuo al richiesta
            reader: myReader //oggetto JSONreader
      }),
      columns: [
         {header: 'ID', width: 120, sortable: true, dataIndex: 'id'},
         {header: 'Name', width: 120, sortable: true, dataIndex: 'name'},
      ],
      viewConfig: {
         forceFit: true
      },
      renderTo: 'content',
      title: 'mannaggia de la pulchiacchera!!!!',
      width: 500,
      height: 500,
      frame: true
   });

   grid.getSelectionModel().selectFirstRow();
});

- and the html:
<html>
<head>
    <title>Grid</title>
   
    <!– Include Ext and app-specific scripts: –>
    <script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../ext-all-debug.js"></script>
    <script type="text/javascript" src="griglia.js"></script>
   
    <!– Include Ext stylesheets here: –>
    <link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css">
    <link rel="stylesheet" type="text/css" href="griglia.css">
</head>
<body>
   <h1>Griglia dinamica</h1>
   <div id="content">
   </div>

</body>
</html>

The html return an empty grid! what is the problem?????? thanks!
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
I suspect your JSON is invalid, as there are no commas after each array entry. Also, each property must be "double quoted". Also you need to make sure it's escaped correctly.

Try
<#escape x as jsonUtils.encodeJSONString(x)>
{
   "total": ${total},
   "rows": [
   <#list nodes as document>
           {"id": "${document.nodeRef}", "name": "${document.name}"}<#if document_has_next>,</#if>
   </#list>
   ]
}
</#escape>

http://www.jsonlint.com/ is your friend  :wink:

Thanks,
Mike

marcuzzo86
Champ in-the-making
Champ in-the-making
nothing, it doesn't work. more suggestions?

thanks a lot! Smiley HappySmiley HappySmiley Happy

mikeh
Star Contributor
Star Contributor
Use the Firebug add-in for Firefox and debug what's going on. Also, the ExtJS community might provide further help, as I guess it's an ExtJS issue, not an Alfresco one.

Thanks,
Mike

marcuzzo86
Champ in-the-making
Champ in-the-making
ok, ill'try in EXTJS community. thank you mike! Smiley Happy