Forum


19:06

26/01/2010

Hi. Im implenting struts &jquery.
my action will return a JSON string to my jsp. What do I need to do to access the JSON string after the ajax call has already been made?
I am implementing the grid. I have added serveral key/value pairs in my JSON string that will NOT be in the grid.
And I want to use these extra values to implement some logic after the ajax callis complete.
I have put onCompleteTopics="complete" in my grid. This calls:
$.subscribe('complete', function(data){
var res = jQuery.getJSON();
alert(rest);
});
Howevers, res is not my JSON string that is returned to the jgrid by my action.
Any one with ideas how I can access the json string that org.apache.struts2.json.JSONUtil serlializes and sends to the jsp?
merci
17:30

Moderators
30/10/2007

Hello,
Use loadComplete - the parameter passed to it is the request
loadComplete : function(request)
{
// do somthing here with the request
}
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
08:51

Moderators
30/10/2007

Hello,
You shoud use request directly, and not request.responsText
try alert(request);
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
11:24

Moderators
30/10/2007

Hello,
Sorry it was my mistake. Of course it is a object.
If you know some property of this object you can
alert(request.myobjectname);
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:01

05/01/2011

Hi Tony,
I have a similar issue as mentioned in the discussion above. Making use of the following in the application:
1) Struts 1.2
2) JQGrid 3.8.2
3) JQuery 1.4.4
The Struts action method returns a json object after obtaining data from the database. See code below:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
...
...
JSONObject jsonObj = createJSONTestData();
response.setHeader("X-JSON", jsonObj.toString());
System.out.println("Final JSON OBj: " + jsonObj.toString());
return mapping.findForward(sForward);
}
/*
*This piece of code is the same as the php code mentioned in one of the examples
*provided in jqgrid demos
*/
public JSONObject createJSONTestData() {
....
....
//Hit the database and obtain the resultset and create the json object
JSONObject responcedata=new JSONObject();
net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();
responcedata.put("total","3");
responcedata.put("page",cpage);
responcedata.put("records","2");
net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();
int i=1;
while(rs.next()){
cellobj.put("id",rs.getInt(1));
cell.add(rs.getInt(1));
cell.add(rs.getString(2));
cell.add(rs.getString(3));
cellobj.put("cell",cell);
cell.clear();
cellarray.add(cellobj);
i++;
}
PrintWriter out = response.getWriter();
responcedata.put("rows",cellarray);
return responcedata;
}
The struts-config.xml action forward mapping points to an empty.jsp that has no specific code.
The jsp file formulates the jqgrid as shown below:
$(document).ready(function(){
$("#load_callback1").click(function(){
jQuery("#list10").jqGrid({
url:'/TestJSON/testAction.do?method=getJSONData',
datatype: "json",
colNames:['Invoice Number','Invoice Date','Invoice Name'],
colModel:[
{name:'id',index:'id', id:'id',width:90},
{name:'invdate',index:'invdate', width:120},
{name:'invname',index:'invname', width:200}
],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'invname',
sortorder: "desc",
caption:"JSON Example"
}).navGrid('#pager1',{edit:false,add:false,del:false});
});
});
The grid comes up with no data. A similar example works well with the doGet method of a servlet.
Questions:
1) How do we obtain the json object returned from a struts action method?
2) Is there any process to be done in the empty.jsp file to handle the response object and obtain the json data?
Not sure if I posted the question under the right topic. Awaiting for a clarification at the earliest. Thank you.
Regards,
Aarati
Regards,
Aarati
Most Users Ever Online: 715
Currently Online:
53 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66