Amar-ms
asked on
send JSON object to JSP from a spring MVC
I am trying to convert a java object to JSON and send it to my jsp (actually jqgrid-jquery object is expecting this JSON) the project is using spring framework.
Any code examples will be extremely helpful.
Any code examples will be extremely helpful.
Can u post ur Layout ???
as per layout only we can set the value ...
as per layout only we can set the value ...
1.set ur values in one bean (what ever u want display)!!
2. passes to view Class .
3.that view calss return JSon Object to ur jsp.
4.ur layout take care of to dispaly the values !!
i think this will help full if u need i will give code !!
2. passes to view Class .
3.that view calss return JSon Object to ur jsp.
4.ur layout take care of to dispaly the values !!
i think this will help full if u need i will give code !!
Examples
i think u know the 1st step i mention in the last command !!
lIst having beans .
List userDetails=papaUserManage mentInter. getUserDet ails();
map.put("userDetails", userDetails);
return new ModelAndView(new userView(), map);
i think u know the 1st step i mention in the last command !!
lIst having beans .
List userDetails=papaUserManage
map.put("userDetails", userDetails);
return new ModelAndView(new userView(), map);
public class userView implements View{
public String getContentType() {
return "text/json";
}
@SuppressWarnings("unchecked")
public void render(Map model, HttpServletRequest arg1,
HttpServletResponse response) throws Exception {
response.setContentType("text/json");
response.setCharacterEncoding("UTF-8");
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Calendar.class, new CalendarJsonValueProcessor());
List userDetails = (List)model.get("userDetails");
Map map1 = new HashMap();
map1.put("identifier", "userCode");
map1.put("urModelName", userDetails);
JSONObject jsonBulletin = JSONObject.fromObject(map1, jsonConfig);
PrintWriter writer = response.getWriter();
writer.print(jsonBulletin .toString());
}
}
i have copied this jqGrid where i mention in the link
colModel:[ {} ], this part only having value .
map1.put("colModel", userDetails);
u mention like this !!
colModel:[ {} ], this part only having value .
map1.put("colModel", userDetails);
u mention like this !!
jQuery("#rowed1").jqGrid({
url:'server.php?q=2',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[ {} ],
rowNum:10,
rowList:[10,20,30],
pager: '#prowed1',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
editurl: "server.php",
caption: "Basic Example" });
Just try !!
ASKER
Hi Dravidnsr,
thanks for taking your time to explain this.. but i need some more help. how do i configure the view and the controller/bean etc in the xml also if you please paste a simple controller/ bean and all the wiring in the xml.. i am new to spring and its a bit hard for me to grasp the 4 steps u mentioned above.
thanks a bunch for your help.
thanks for taking your time to explain this.. but i need some more help. how do i configure the view and the controller/bean etc in the xml also if you please paste a simple controller/ bean and all the wiring in the xml.. i am new to spring and its a bit hard for me to grasp the 4 steps u mentioned above.
thanks a bunch for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i think others 2 step are u know
http://jackson.codehaus.org/Tutorial