I have looked at many examples and various forum postings but still can not get the grid to display data. All I get is ? in the grid. Here is the code:
memberView = {
cells: [[
{ name: 'Name', field: "name" },
{ name: 'Address', field: "address" },
{ name: 'Birth Date', field: "birthDate" },
{ name: 'Gender', field: "gender" },
{ name: 'State', field: "state" }
]]
};
bsbOnClick = function() {
dojo.xhrGet({
url: "FindMemberAjax.do",
handleAs: "text",
content: {
lastName: dojo.byId("msLastName").value,
firstName: dojo.byId("msFirstName").value,
birthDate: dojo.byId("msBirthDate").value
},
load: function(resp, ioArgs){
try{
personArray = eval("(" + resp + ")");
var grid = dijit.byId("grid");
var store = new dojo.data.ItemFileReadStore({data: personArray });
var gridModel = new dojox.grid.data.DojoData(null, store, {query:{name: '*'}, clientSort:true});
grid.setModel(gridModel);
grid.refresh();
}catch(e){
alert("error in load function: " + dumpObj(e));
}
return resp;
and html code
<div id="mainTab" class="tundra" dojoType="dijit.layout.ContentPane" layoutAlign="client">
<div dojoType="dijit.layout.TabContainer" style="height: 100%; width: 100%;">
<div dojoType="dijit.layout.ContentPane" title="Info">
<div dojoType="dojo.data.ItemFileReadStore" jsId="gridDataStore" id = "gridDataStore"></div>
<div dojoType="dojox.grid.data.DojoData" jsId="gridModel" id = "gridModel" store="gridDataStore" query = "{ name : '*'}"></div>
<div dojoType="dojox.Grid" jsId = "grid" id="grid" model="gridModel" structure="memberLayout"><div>
test
</div>
<div dojoType="dijit.layout.TabContainer" style="height: 100%; width: 100%;">
<div dojoType="dijit.layout.ContentPane" title="Info">
<div dojoType="dojo.data.ItemFileReadStore" jsId="gridDataStore" id = "gridDataStore"></div>
<div dojoType="dojox.grid.data.DojoData" jsId="gridModel" id = "gridModel" store="gridDataStore" query = "{ name : '*'}"></div>
<div dojoType="dojox.Grid" jsId = "grid" id="grid" model="gridModel" structure="memberLayout"><div>
test
</div>
and data from FindMemberAjax.do call looks like:
[{"__object_name": "personInfo","address": "2191 VAN DYKE #2","birthDate": "1977-07-23","city": "MAPLEWOOD"
,"class": "com.cob.ajax.beans.PersonInfo","gender": "F","maritalStatus": "","name"
: "LISA JONES","state": "PA","zip": "55109
What am I doing wrong? Any help would be greatly appreciated. . .

What error are you getting?
What error are you getting? As far as I can tell your data isn't properly formatted for the data store. Here is an example of the type of format it expects to receive
JSON format
Type of format
Thank you for your response. I've read and reviewed the JSON format. I am not getting an error, I just get question marks in the grid. My question is then how do I get the object into the JSON format? I tried adding this but with the same results.
personArray = {
identifier: "name",
label: "name",
items: [
{"__object_name": '',
"address": '',
"birthDate": '',
"city": '',
"class": '',
"gender": '',
"maritalStatus": '',
"name": '',
"state": '',
"zip": ''}]
};
Can you please guide me in the right direction?
Well if you use Firefox with
Well if you use Firefox with Firebug it will give you a console which will tell you what Dojo error you are getting. As far as the JSON data goes if you are using a Servlet you can have something like this.
throws ServletException, IOException {
Set aps = new AvailableProgramGridManager().getAvailablePrograms();
JSONSerializer serializer = new JSONSerializer();
PrintWriter out = response.getWriter();
response.setContentType("text/json");
out.println("{\"identifier\": \"id\",");
out.println("\"label\" : \"programName\",");
out.println("\"items\":");
out.println(serializer.serialize(aps));
out.println("}");
}
Then you can access the data through a URL.
Correct JSON Format
I changed the servlet executeAction to include the above mentioned code which formatted the response, correct? In firebug the response now looks like:
{"identifier": "name",
"label" : "name",
"items": [
{"__object_name": "personInfo","address": "2191 VAN DYKE #2","birthDate": "1977-07-23","city": "MAPLEWOOD"
,"class": "com.cob.ajax.beans.PersonInfo","gender": "F","maritalStatus": "","name"
: "LISA JONES","state": "MN","zip": "55109"}
]}
I have changed the code:
bsbOnClick = function() { dojo.xhrGet({ url: "FindMemberAjax.do", handleAs: "text", content: { lastName: dojo.byId("msLastName").value, firstName: dojo.byId("msFirstName").value, birthDate: dojo.byId("msBirthDate").value }, load: function(resp, ioArgs){ try{ personArray = eval("(" + resp + ")"); var grid = dijit.byId("grid"); var store = new dojo.data.ItemFileReadStore({url: personArray });//Modified line var gridModel = new dojox.grid.data.DojoData(null, store, {query:{name: '*'}, clientSort:true}); grid.setModel(gridModel); grid.refresh(); ...but now I am getting an error bad http response code:404 message because of the URL. How do I correctly access the data through the URL?
Thank you,
er
Generally you just need to
Generally you just need to point it to the mapping of the servlet. So it would be something like
http://localhost:[port number]/applicationName/ServletMappingName
It uses GET so you have to make sure you handle it there, or call POST from your GET method.
Using Action Struts through Ajax
I mapped the servlet as suggested however my server side java code called GetPersonAjaxAction extends AjaxAction and I am getting a class GetPersonAjaxAction is not a servlet error and ClassCastException. Is there a way to send the json formatted data from the server to dojo.xhrGet (or Post)? I wanted to use ItemFileReadStore but is this possible?
Thank you.
as long as you can map the
as long as you can map the url to the datasource you should be fine. You just need a url that maps to a json datasource which is properly formatted.