Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSON Object and Java Script DropDown

 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to populate a dropdown box using JSON response from a Portlet.Help me with a code.

How can I do it with JSONObject,to contain all those options and its values.

Help me with a code.

Thanks
Ashok
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You first. What have you written so far? Where is it giving you problems? What is the format of your JSON? If you haven't designed it yet, what kind of data do you think it should contain?

Show some effort.
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i created some thing like this.

import net.sf.json.JSONObject;

JSONObject json = new JSONObject();
json.put("key", title);
json.put("value", developer);


I need to add multiple objects to populate in JSP as a Dropdown.

Thanks
Ashok
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And are you doing this with Ajax? Have you done a basic tutorial on how to make an Ajax call?

Eric
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing AJAX on liferay portal and I am trying to create JSONOBject from my databean on server side and send it to client , parse it, iterate and display on another dropdown.
I am trying to figure out 2 issues
1. how to create JSON on server side from bean.
2. How to parse and iterate it on client side

Thansk for help
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well parsing it is easy if you are able to use a library such as jQuery



if you are not using a library you need to use something like json.js or eval

Than you can add options to your select using new Option

Eric
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply,

Sorry i missed to mention that I am using dojo for making server call via dojo.io.bind(.., that gets json from server, I am new to dojo so I am trying to find the dojo parser,
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used JSON.parse and got the parse done. I will proceed to create options, Thanks for help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic