| | |
send a function in a JSON through java
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 18
Reputation:
Solved Threads: 3
Hello everyone,
first of all, I dont know if this should be in the java or the jsp forum. I put it here since is a web related question.
I am making a report module for a web page using java. For this I will use a jquery plugin called datatables (I'm not sure if it's allowed to link to it). The point is that I need to generate a json string dynamically in order to get my reports.
The problem is that along with my data I will also have to send some anonymous functions in the json. I have used some libraries to convert java objects to a json string but nothing on how to send a function.
The jsons will look something like this:
I know I can generate it manually as a string, but that seems quite complex and I would like to keep that as a las resort.
Anyone knows a library that can generate javascript functions from java?
Thank you for any help you can provide me. This place looks quite nice btw
first of all, I dont know if this should be in the java or the jsp forum. I put it here since is a web related question.
I am making a report module for a web page using java. For this I will use a jquery plugin called datatables (I'm not sure if it's allowed to link to it). The point is that I need to generate a json string dynamically in order to get my reports.
The problem is that along with my data I will also have to send some anonymous functions in the json. I have used some libraries to convert java objects to a json string but nothing on how to send a function.
The jsons will look something like this:
JSP Syntax (Toggle Plain Text)
{ "aoColumns": [ { "sTitle": "Column 1" }, { "sTitle": "Column2" }, { "sTitle": "Column3" }, { "sTitle": "Column centered", "sClass": "center" }, {"sTitle": "Column rendered", "sClass": "center", "fnRender": function(obj) { var sReturn = obj.aData[ obj.iDataColumn ]; if ( sReturn == "A" ) { sReturn = "<b>A</b>"; } return sReturn; } } ] }
I know I can generate it manually as a string, but that seems quite complex and I would like to keep that as a las resort.
Anyone knows a library that can generate javascript functions from java?
Thank you for any help you can provide me. This place looks quite nice btw
0
#2 20 Days Ago
I am not sure sure if this will help, but i had done something a similar, what i did is create a json string using javascript on my jsp page after button was clicked, then sent the json string using ajax to a servlet. In the servlet i used request.getParameter to get the json string, then looped over it using the libraries from the json.org site
Life... Is a Moment
•
•
Join Date: Oct 2009
Posts: 18
Reputation:
Solved Threads: 3
0
#3 20 Days Ago
I think I have a decent solution. I got the libraries from json.org and modified the JSonWriter class to add a function method that will receive a string with the javascript function. I still have to generate the function by hand, but It's better than nothing.
It's quite simple, the string is composed of the arguments and the function body:
It's quite simple, the string is composed of the arguments and the function body:
JSP Syntax (Toggle Plain Text)
public JSONWriter function(String function) throws JSONException{ if(this.mode=='o' ) { //this.push(null); this.append("function "+function); this.comma=true; return this; } throw new JSONException("Misplaced function."); }
![]() |
Similar Threads
- put the Dos 's command into java program? (Java)
- Socket passing double type value from c++ to java (Java)
- Iterating over JSON object (JavaScript / DHTML / AJAX)
- hashing function help using Java (Java)
- Windows socket questions (send()) (C)
- Help on Gamma Function (Computer Science)
- ASP, Java and XML-RPC (ASP)
- repost, function alogorithm problem (C)
Other Threads in the JSP Forum
- Previous Thread: hi~need some help~
- Next Thread: Problem in running JSP
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





