Skip to main content

loop error in dojo.table

3 replies [Last post]
muneer123
Offline
Joined: 2008-09-22

i am building a dynamic table with the help of

in data.jsp i send data
String a = "aaa";
String b = "bbb";
int c = 123;
int d = 456;
int i = 0;

out.print("value=" + "{columns : [ { label : '" + a + "', id : 'title'}, " +
"{ label :'" + b + "', id : 'author'}," +
" { label : '" + c + "', id : 'isbn'}," +
" { label : '" + d + "', id : 'description'}],");
out.print(" rows : [ { title : '" + a + "', author : '" + b + "', isbn: '" + c + "', description : '" + d + "'} ] }");

when i write data with loop like
String a = "aaa";
String b = "bbb";
int c = 123;
int d = 456;
int i = 0;

out.print("value=" + "{columns : [ { label : '" + a + "', id : 'title'}, " +
"{ label :'" + b + "', id : 'author'}," +
" { label : '" + c + "', id : 'isbn'}," +
" { label : '" + d + "', id : 'description'}],");
while (i < 2) {
out.print(" rows : [ { title : '" + a + "', author : '" + b + "', isbn: '" + c + "', description : '" + d + "'} ] }");
i++;
}

it give me error
Data format error loading data from data.jsp
give me some helpfull advise

Message was edited by: muneer123

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sloanb
Offline
Joined: 2003-09-14

In your loop you should be writing the following:

[code]
{ title : '" + a + "', author : '" + b + "', isbn: '" + c + "', description : '" + d + "'}
[/code]

You are writing out an array each time. An example would be:

[code]
// Write the columns
out.print("{columns : [ { label : '" + a + "', id : 'title'}, " +
"{ label :'" + b + "', id : 'author'}," +
" { label : '" + c + "', id : 'isbn'}," +
" { label : '" + d + "', id : 'description'}],");

// Write out row data
out.print("rows : [");
for (int i=0; i < 2; i++)
{
out.print("{ title : '" + a + "', author : '" + b + "', isbn: '" + c + "', description : '" + d + "'}

}
out.print("]}");
[/code]
You would also probably want to look into the JSON package. With it you can write json easily using normal pojo objects. (JSONObject, JSONArray)

Message was edited by: sloanb

muneer123
Offline
Joined: 2008-09-22

thank you
can you tell me where i study about JSON?
thanks in advance

sloanb
Offline
Joined: 2003-09-14

Test best place to start is http://www.json.org. Let us know if you have any questions.