Handling Map using <Json:array> tag

698 views
Skip to first unread message

nithin

unread,
Feb 24, 2008, 1:24:40 AM2/24/08
to json-taglib
Hi,

I have a "Map" returned from a java method to JSP.I want to add the
map to the Json Object. could you please help me in this regard.

DataBeanObject : userProfileBean ( UserProfileDataBean)
Map name= address
Key = addressBean (JavaBean object has name,nick name properties)
value = phone numbers (List)


The json object should look as follows :

{"addressbook": {"name": "Tony",
"nick name" :"Tom"
"phoneNumbers": [
"619 332-3452",
"664 223-4667"
]
}
}

In the above example. The name,nickname,are to be retrieved from
JavaBean object (key of the map )and phonenumbers is list (value of
the map)

<json:object name="addressbook">
<json:property escapeXml="false" name="name" value="$
{userProfileBean.address.key.name}"/>
<json:property escapeXml="false" name="nick name" value="$
{userProfileBean.address.key.nickName}"/>
<json:array name="phoneNumbers" var="phoneNumbers" items="$
{userProfileBean.address.value}">
<json:object>
<json:property name="phoneNumber" value="$
{phoneNumbers.phoneNumber}"/>
</json:object>
</json:array>
</json:object>

The Json object for the above code is created as below,

{"addressbook":{"name":"",
"nick name":"",
"phoneNumber":[]
}

Could you please tell me, where i went wrong in retrieving values?

l...@emailnot.com

unread,
Feb 25, 2008, 6:52:16 AM2/25/08
to json-taglib

> Could you please tell me, where i went wrong in retrieving values?

Sure you find your value by
userProfileBean.getAddress().getKey().getNickName()?
As long as you have fixed keynames, why don't you use getter methods?

I have a feature request which would solve your problem too .. but
more elegantly. What we have is a HashMap whose keys may change
frequently and we want the object to render all the key-value-pairs
from this HashMap as properties. Similar to constructing a
org.json.JSONObject with a initializing Map.
So long we have to iterate over the keys with jsp functionality which
is not really nice.
Reply all
Reply to author
Forward
0 new messages