AJAX Forums

Mapping hashMap of Java to javascript object(DWR framework)

This is a discussion on Mapping hashMap of Java to javascript object(DWR framework) within the Ajax Frameworks forums, part of the Advanced Ajax category; i needed to use hash map in javascript for my application using DWR. If you know DWR enables you to call java method in your javascript code. In my case ...


Go Back   AJAX Forums > Advanced Ajax > Ajax Frameworks

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Old 11-23-2007, 04:11 AM   #1 (permalink)
Junior Member
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0 aryan8481 is on a distinguished road
Lightbulb Mapping hashMap of Java to javascript object(DWR framework)

i needed to use hash map in javascript for my application using DWR. If you know DWR enables you to call java method in your javascript code. In my case the return type of method was hashMap so had map it and iterate it.

This is how I did it.

PersonVO is just a java class which gives me hashMap of Java. I call a method of it 'maptest' using DWR. The maptest method looks like this:

//-------java code-----------
public Map maptest(String id)
{
HashMap key = new HashMap();
key.put("key","vvaf");

return key;
}

In my javascript i make a call to this method using DWR(AJAX framework) engine which returns me a hashMap. The hashMap goes in data object. You can store it in any variable(var) of javascript. Use for ..in loop to find the key's existence in map. The important part is accessing value like you access value from an array object of javascript. Here you specify key instead of index.


//--------javascript code----------
PersonVO.maptest(fn,callback=function(data){
var key = new String("key");
for(key in data)
{
//accessing value from data map
alert(data["key"]);
}
});
__________________
keyur
aryan8481 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes



All times are GMT -4. The time now is 03:11 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5
Copyright ©2006 - 2008, AJAXwith.com