Iterating a JSON Object and displaying Datatable

Iterating a JSON Object and displaying Datatable

jacob1983jacob1983 Posts: 1Questions: 0Answers: 0
edited December 2012 in General
i have an HTML form with muliple user inputs and a submit button. I need to pass the parameters selected to a Servlet and then search the
resultset with the input parameters and then construct a datatable without page refresh.

I was able to complete the data retrieval part . Create the JSP form , invoke the Servlet by using Jquery but i am not able to create the datatable with the server data.

I am getting List from the Server . but right now i need to only display requestHeader on the Table.

[code]
public class PackOutRqstData implements Serializable
{
private VwPackOutRqstSum requestHeader = null;
private List requestDetail = null;
}

public class VwPackOutRqstSum implements Serializable {

private BigDecimal packOutRqstGid;
private Date rqstTms;
private BigDecimal fromStorNum;
private String usrId;
private BigDecimal ttlRqstQty;
private BigDecimal ttlMovedQty;
private BigDecimal packOutSttsCdGid;
}

public class PackOutRqstItm implements Serializable{

private BigDecimal packOutRqstItmGid;
private BigDecimal packOutRqstGid;
private String itmNum;
private BigDecimal rqstQty;
private BigDecimal movedQty;
private BigDecimal dstrnNum;
private BigDecimal packOutSttsCdGid;
private BigDecimal packOutReasnCdGid;
private Date insrtTms;
private String insrtPgmNam;
private Date lastUpdTms;
private String lastUpdPgmNam;
}
[/code]

Java Script
[code]

$('#example').dataTable();
"sScrollY"; "200px",
"bPaginate"; true;

$("#submit").click(function blabla() {
var formData = $('form').serialize();
$.ajax( {
type: "POST",
url: "SearchServlet",
data: formData,
dataType: "json",
success: function(data) {
// Not Sure how to build the table from JSON

}
});
[/code]

The HTMLresult table
[code]


Packout Request #
Requested Date
From
SKU
QTY Requested
QTY Moved
Reason Code
Status







[/code]

Servlet
[code]
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


PrintWriter out = response.getWriter();
response.setContentType("text/html");
response.setHeader("Cache-control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "-1");

response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
response.setHeader("Access-Control-Max-Age", "86400");


String code = (String) request.getParameter("code");
System.out.println("***** "+ code);
String fromDate = (String) request.getParameter("fromDate");
System.out.println("***** "+ fromDate);
String toDate = (String) request.getParameter("toDate");
System.out.println("***** "+ toDate);
String output = "Code "+ code+ " From Date "+fromDate + " to date "+toDate;
System.out.println(output);

Gson gson = new Gson();
JsonObject myObj = new JsonObject();


List packOutRqstDatas = DataRepository
.getPackoutRequestData(null);

JsonElement jsonObject = gson.toJsonTree(packOutRqstDatas);

if (jsonObject == null) {
myObj.addProperty("success", false);
} else {
myObj.addProperty("success", true);
}
myObj.add("jsonObject", jsonObject);
out.println(myObj.toString());
out.close();

}
[/code]

JSON Object for reference
[code]
[{"requestHeader":{"packOutRqstGid":123456,"rqstTms":"Dec 3, 2012 11:35:17 PM","fromStorNum":555,"usrId":"ivin","ttlRqstQty":100,"ttlMovedQty":50,"packOutSttsCdGid":1},"requestDetail":[{"packOutRqstItmGid":1,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"},{"packOutRqstItmGid":2,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"}]},{"requestHeader":{"packOutRqstGid":654321,"rqstTms":"Dec 3, 2012 11:35:17 PM","fromStorNum":444,"usrId":"ivin","ttlRqstQty":100,"ttlMovedQty":50,"packOutSttsCdGid":1},"requestDetail":[{"packOutRqstItmGid":3,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"},{"packOutRqstItmGid":4,"packOutRqstGid":123456,"itmNum":"101","rqstQty":100,"movedQty":50,"dstrnNum":777,"packOutSttsCdGid":1,"packOutReasnCdGid":1,"insrtTms":"Dec 3, 2012 11:35:17 PM","insrtPgmNam":"ivin","lastUpdTms":"Dec 3, 2012 11:35:17 PM","lastUpdPgmNam":"ivin"}]}]
[/code]
This discussion has been closed.