JQGRID in spring mvc and hibernate

1.3k views Asked by At

How to show data from oracle 10g table in a jqGrid using spring and hibernate? There are some data present in the table and I want to show them in a editable jqGrid table in jsp. can anyone guide me how to do it.

protected ModelAndView onSubmit(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors)
                throws Exception {
    rel_details reldetails = (rel_details) command;
    List l=reldetailsdao.save_release_details(reldetails);

    JSONObject responseDetailsJson = new JSONObject();
    JSONArray jsonArray = new JSONArray();

    Iterator itr=l.iterator();
    rel_details asd=null;
    while(itr.hasNext()){
        asd=(rel_details)itr.next();

        JSONObject formDetailsJson = new JSONObject();
        formDetailsJson.put("rel_id", asd.getRel_id());
        formDetailsJson.put("rel_name", asd.getRel_name());
        formDetailsJson.put("rel_modified_date", asd.getRel_modified_date());
        formDetailsJson.put("rel_desc", asd.getRel_desc());
        formDetailsJson.put("rel_env", asd.getRel_env());
        formDetailsJson.put("rel_change_req_no", asd.getRel_change_req_no());
        formDetailsJson.put("rel_status", asd.getRel_status());
        jsonArray.add(formDetailsJson);
    }

    responseDetailsJson.put("l", jsonArray);
    System.out.println(responseDetailsJson);

    return new ModelAndView("add_release","rel",responseDetailsJson);
1

There are 1 answers

0
RLD On

You have to go through the below steps to show your result in jqgrid if your technology stack is Java and Spring.

  1. Create a class ResponseDTO that will contain the results and other values that you want to show in jqgrid.
  2. Modify the above onSubmit method to return the response DTO you created just now in step 1. There is no need to use JSONObject or JSONArray class.
  3. Map the onSubmit method to a url and ensure that this method is part of a controller in MVC.
  4. Then create a JSP which will refer the above url as below to show and edit the results.

        $(document).ready(function(){
            $("#list").jqGrid({
                    datatype: 'json',
                    mtype: 'GET',
                    height: 'auto',
                    url:'actual url that retrieves results i.e., url created in step 3',
                    editurl:'actual url through which you want to edit the data',
                    colNames:['Col Name1','Col Name2','Col Name3'],
                    colModel:[]
                    ..................
                    ..................
              })
           })
    
  5. You have to have Jackson jar (e.g., jackson-all-x.x.x.jar) in classpath to do the necessary JSON conversion. Accordingly you have to use @RequestBody and @ResponseBody annotations.

Hope this helps you move forward. In case you have any issue, you can refer the link here.