Dynamic tables in jsp using Spring framework - json

I am working in Spring MVC. These is the scenario..
I select a value from dropdown box and click a button on jsp .
An event is triggered using javascript function.
Based on input,some database queries are executed , records are retrieved and
data is set into JSON Object in controller class.
How can I populate this JSON Object into the same jsp using table .?
Can I populate the same in a new tab.?
If you suggest a solution , then it would be highly helpful for me and my friends..
Thank you...

To work with JOSN object better option is used JQuery and send request to controller using
JQuery and get the JSON object and simple print in html code.
another option is generate html code in controller and send as a response and then simple print that response as a html souce of div.
are you getting me?

Related

How to bring JSON file via URL in Django?

I am new to Django. I have a few independent dropdown boxes. Now I have to get data from the backend in JSON and parse it for each dropdown boxes. How do I do this? How do I bring JSON via URL? how should I make use of Ajax methods here?
Basically, I want to use Ajax method calls and JSON bind data to ui.

HTML form data submitted to embedded mongodb

I want to insert data into a mongodb collection from a HTML Form and I want it to have a specific structure. e.g.
{name:{first_name:"", last_name:""}, address:{street:"",
post_code:""}}
In a normal form submission the data doesn't seem to have structure. Any ideas?
Thanks!
HTML cannot insert into MongoDB directly, you need an application layer, if your application is based on java, you can map the form values into an object of your choice and then save that object in MongoDB.
If you are using nodeJS, it is even easier where you can form the said structure on the frontend and make an ajax call to node server and it can save the passed request as it is into MongoDB.
If you must use HTML form, I think you will have to do the hard work of parsing the HTML data to object of desired structure.

Using HTML Templates at server side

I am working on play framework with SCALA as backend.
Json data is given to the front end from the controller.
I want to add HTML as value of some fields of json.
This HTML will be kept as a template and data will be added in this template at run time.
I think i should put unique names in the HTML template and then these names will be replaced by the data which i want to add at run time. Ultimately, this HTML will be added in the json response.
Is my approach right? If not, what is the best approach to add data in an HTML template,add this template in json response and send this combined response to the front-end for further use?
Is it a good practice to use string replacement to add data in an HTML template?
I think as long as you use Play, you can put your HTML templates into app/views package. Let's say you call your template mytemplate.scala.html
You can parameterize this view as any Play view.
In the place in your code where you generate your JSON response you can then call mytemplate(parameters) to get html generated, Play will do all the work here for you. Then using play.api.libs.json.JSON object's methods and related facilities you can convert this html to JSON.
So in your controller's code you will have something like Ok(JSON.toJson(mytemplate(parameters)))
This is of course a sketch, so you will need to elaborate and try.

ExtJS: Loading data into multiple combobox from a single json using nested model

I have the following scenario:
I have two comboboxes, with different root property.I want to load both comboboxes using same response.
Please provide some solution to accomplish this.
You can refer the fiddle for clear understanding.
https://fiddle.sencha.com/#fiddle/fti
I want to load first combobox with "RetrieveRegionComboList" and second combobox with "RetrieveLanguageComboList", by loading the json only once.
In this fiddle,Iam populating the combobox by making call to JSON twice using nested store in model. I want to achieve the same by using the single response to complete multiple request.
Thank You...
You can load the data in both combos like this :
First, you make an Ajax request, and in the success callback you decode the JSON and load the data into the stores.

Pass Json Object from Play! framework to HighCharts JS

http://www.playframework.com/documentation/2.1.x/JavaTodoList
Using the above tutorial as a reference, I have created an application which sends data from the model to view via the Application controller.
I have managed to display the model(Tasks) as a high chart. The code is here.
public static Result format(){
return ok(views.html.frmt.render("Visualize it",Task.all()));
}
This goes to this view page.
http://ideone.com/ycz9ko
Currently, I use scala templating inside the javascript code itself. Refer to lines 9-14 and lines 20-24.This unelegant style of doing things is not really optimal.
I want to be able to accomplish the above using Json instead.
public static Result jsonIt(){
List<Task> tasks = Task.all();
return ok(Json.toJson(tasks));
}
My Qns are how to send the JSON objects to a view template.
And how to parse it into a Highcharts format. Is there some standard procedure to do this ? Or else I have to write my own method to do this ?
It'll great if someone can show me a code snippet. Also I would prefer a post not using Ajax. I would just want to know how to do this first.
I also found this stackoverflow post useful.how to parse json into highcharts. However, it didnt answer the part about converting from Play format to Highcharts format.
Thanks in advance
You don't need to pass a json object to your template, instead you might do an ajax call from your client side javascript (your template) and get json response that you could use futher in javascript code to build a chart. For example :
You have some path that is bind to your controller jsonIt() like so /chartsdata/json
then using jquery shorthand for ajax request:
var chart_data = $.get('/chartsdata/json', function(data) {
return data;
});
now you can use a chart_data that is an array of objects where each object represents a Task, in your further javascript code to build a chart.