Using json-taglib with jmaki

12 views
Skip to first unread message

Thorleif Wiik

unread,
Sep 30, 2007, 4:41:08 PM9/30/07
to json-taglib
Hi,

just tried to use the json-taglib as JSON Provider for jmaki widgets.

in my index.jsp:

<a:widget name="yahoo.dataTable" service="http://localhost:8080/
jmaki/json.jsp" />


The JSON Format I need is the following:


{columns : [
{ label : 'Title', id : 'title'},
{ label :'Author', id : 'author'},
{ label : 'ISBN', id : 'isbn'},
{ label : 'Description', id : 'description'}
],


rows : [
{ id: 'foo', title : 'Book Title 1', author : 'Author 1', isbn:
'4412', description : 'A Some long description'},
{ id : 'bar', title : 'Book Title 2', author : 'Author 2', isbn :
'4412', description : 'A Some long description'}
]
}


My json.jsp:

<json:object>
<json:property name="outer" value="foo"/>

<json:object name="inner">
<json:property name="innerProp1" value="val1"/>
<json:property name="innerProp2" value="val2"/>

<json:object name="inner2">
<json:property name="inner2Prop1" value="in2p1"/>
<json:property name="inner2Prop2" value="in2p2"/>
</json:object>

</json:object>
</json:object>

will generate json Code, which will no be accepted by jmaki.


Is there any chance to modify the json-taglib, to produce a jmaki
compatible
json format?

--

Regards, Thorleif Wiik

James Wiltshire

unread,
Oct 1, 2007, 5:56:00 AM10/1/07
to json-taglib
Hi Thorleif,

JSON-taglib should be capable of producing any JSON data that you
require. JSON itself is only a data interchange format, so there isn't
anything that needs to be done to the library to produce JSON that is
'compatible' with jmaki (or any other component that consumes JSON
data). It's just a matter of producing the data in the format that is
expected by the consuming component.

You should be able to render the data in the format that you need
using something like the following:

<json:object>

<json:array name="columns" items="${columns}" var="column">
<json:object>
<json:property name="label" value="${column.label}"/>
<json:property name="id" value="${column.id}"/>
</json:object>
</json:array>

<json:array name="rows" items="${rows}" var="row">
<json:object>
<json:property name="id" value="${row.id}"/>
<json:property name="title" value="${row.title}"/>
<json:property name="author" value="${row.author}"/>
<json:property name="isbn" value="${row.isbn}"/>
<json:property name="description" value="${row.description}"/>
</json:object>
</json:array>

</json:object>

This example assumes that you have a 'columns' and 'rows' EL variable
available within the page.
Hope this helps!

Regards
James Wiltshire

Reply all
Reply to author
Forward
0 new messages