kendo cannot read property slice of undefined

2 posts, 0 answers
  1. Janice
    Janice avatar
    1 posts
    Member since:
    Sep 2015

    Posted 02 Sep 2015 Link to this post

    Hi, I have encountered this problem when I run my project.

    This is my jsp page.
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
     
         
    <title>Compliance Check Report</title>
    <script type="text/javascript" src="telerik/js/jquery.min.js"></script>
    <script type="text/javascript" src="telerik/js/kendo.all.min.js"></script>
    <script type="text/javascript" src="telerik/js/angular.min.js"></script>
     
    <link href="telerik/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="telerik/styles/kendo.dataviz.min.css" rel="stylesheet" />
    <link href="telerik/styles/kendo.blueopal.min.css" rel="stylesheet" />
    <link href="telerik/styles/kendo.dataviz.blueopal.min.css" rel="stylesheet" />
    <style scoped>
            .k-grid {font-size:10px}
        </style>
    </head>
    <body>
     
                <div id = "compliance_check">
                    <P>
                        <label for="domain">Domain Name: </label><input id="domain_name"
                            style="width: 300px" style="height:10px" />
                    <p>
                    <p>
                        <label for="from">From (m/dd/yyyy): </label><input id="date" style="width: 350px" />
                    </p>
                    <p>
                        <label for="to">To (m/dd/yyyy): </label><input id="date2" style="width: 300px" />
                    </p>
     
                    <p><button class="k-button" id="submit">Submit</button></p>
                    <p></p>
                    <div id="complianceCheck"></div>
                     
                     
                     
                </div>
                 
             
            <script>
            $(document).ready(function() {
                  function startChange() {
                    var startDate = from.value(),
                    endDate = to.value();
     
                    if (startDate) {
                        startDate = new Date(startDate);
                        startDate.setDate(startDate.getDate());
                        to.min(startDate);
                    } else if (endDate) {
                        from.max(new Date(endDate));
                    } else {
                        endDate = new Date();
                        from.max(endDate);
                        to.min(endDate);
                    }
                }
     
                function endChange() {
                    var endDate = to.value(),
                    startDate = from.value();
     
                    if (endDate) {
                        endDate = new Date(endDate);
                        endDate.setDate(endDate.getDate());
                        from.max(endDate);
                    } else if (startDate) {
                        end.min(new Date(startDate));
                    } else {
                        endDate = new Date();
                        from.max(endDate);
                        to.min(endDate);
                    }
                }
     
                var from=$("#date").kendoDatePicker({
                  
                  change: startChange,
                  parseFormats: ["yyyyMMdd"]
              }).data("kendoDatePicker");
     
              var to = $("#date2").kendoDatePicker({
                  
                  change: endChange,
                  parseFormats: ["yyyyMMdd"]
              }).data("kendoDatePicker");
     
              from.max(to.value());
              to.max(to.value());
              $("#submit").click(function() {
                var domain_name=$('#domain_name').val();
                var date=kendo.toString(from.value(),"yyyyMMdd");
                var date2 = kendo.toString(to.value(),"yyyyMMdd");
                 
                 
                function createGrid(){
                    $("#complianceCheck").kendoGrid({
                          dataSource: {
                             
                              transport: {
                                read: {
                                      dataType: "json",
                                      
                                      url: "http://cdctst1c:12010/complianceCheckReport/GetComplianceCheck",
                                      
                                      data: {domain_name:domain_name,date:date,date2:date2},
                                  }
                              },
                              schema: {
                                data: "Compliance_Check",
                                 
                              },
                              pageSize: 7,
                               
                          },
                          width: 800,
                          height: 300,
                          filterable: true,
                          sortable: true,
                          resizable: true,
                          columns: [{
                                      field:"group",
                                      title: "Group",
                                      filterable: true
                                  }, {
                                      field:"date1",
                                      title: "Date1",
                                      filterable: true
                                  }, {
                                      field:"date2",
                                      title: "Date2",
                                      filterable: true
                                  }]
                      });
                     
                }
                $(document).ready(createGrid);
                $(document).bind("kendo:skinChange", createGrid);
                var complianceCheckHist = $("#complianceCheck").data("kendoGrid");
                complianceCheckHist.dataSource.fetch(function(){
                    var element = document.getElementById("compliance_check");
                    if(this.data().length<=0){
                        var textnode = document.createTextNode("No Data");
                        if(element.firstChild.nodeValue!="No Data")
                            element.insertBefore(textnode,element.childNodes[4]);
                        else
                            element.firstChild.nodeValue="No Data";
                    }else{
                        if(element.firstChild.nodeValue=="No Data");
                            element.firstChild.nodeValue="";
                         
                    }
                })
              });
           });
            </script>
        </div>
    </body>
    </html>


    Below is the GetComplianceCheck.java, which is called by the jsp.

    package domain;
     
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.util.Properties;
     
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import org.json.simple.JSONArray;
    import org.json.simple.JSONObject;
     
    import splunk.SplunkConnect;
     
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.splunk.Event;
    import com.splunk.JobExportArgs;
    import com.splunk.MultiResultsReaderJson;
    import com.splunk.SearchResults;
    import com.splunk.Service;
     
    /**
     * Servlet implementation class GetDumpData
     */
    public class GetComplianceCheck extends HttpServlet {
        private static final long serialVersionUID = 1L;
     
        /**
         * @see HttpServlet#HttpServlet()
         */
        public GetComplianceCheck() {
            super();
            // TODO Auto-generated constructor stub
        }
     
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        @Override
        protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
            doPost(req, resp);
        }
     
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        @Override
        protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
            // login to splunk
            Service service = SplunkConnect.Connect();
             
             
            String domain = req.getParameter("domain_name");
            String earliest1 = req.getParameter("date");
            String latest1 = req.getParameter("date2");
             
             
            resp.setContentType("text/plain");
            final PrintWriter out = resp.getWriter();
     
            String json = "";
     
            InputStream inputStream = null;
            InputStream input = null;
            Properties splunkProp = new Properties();
            Properties prop = new Properties();
            String search = "";
     
            try {
                 
                inputStream = new FileInputStream(new File("/appl/eap/project_files/complianceCheckReport/complianceCheckReport_conf.prop"));
                prop.load(inputStream);
                input = new FileInputStream(new File(prop.getProperty("splunk_conf")));
                splunkProp.load(input);
     
                String query = splunkProp.getProperty("getComplianceCheck");
                 
                search = query.replaceAll("domain=a", domain);
                search = search.replaceAll("earliest=earliest1", "earliest=" + earliest1);
                search = search.replaceAll("latest=latest1", "latest=" + latest1);
     
            } catch (final IOException ex) {
                ex.printStackTrace();
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (final IOException e) {
                        e.printStackTrace();
                    }
                }
                if (input != null) {
                    try {
                        input.close();
                    } catch (final IOException e) {
                        e.printStackTrace();
                    }
                }
            }
     
            JobExportArgs jobArgs = new JobExportArgs();
     
            jobArgs.setEarliestTime("-24h");
            jobArgs.setOutputMode(JobExportArgs.OutputMode.JSON);
     
            InputStream exportStream = service.export(search, jobArgs);
             
            try {
     
                ObjectMapper mapper = new ObjectMapper();
                MultiResultsReaderJson multiResultsReaderDomain = new MultiResultsReaderJson(exportStream);
                 
                JSONArray arrays = new JSONArray();
                int countset = 0;
     
                for (SearchResults searchResults : multiResultsReaderDomain) {
                    int count = 0;
                    String resultSetType = searchResults.isPreview() ? "Preview" : "Final";
     
                    if (resultSetType.equals("Final")) {
                        for (Event event : searchResults) {
         
                            String group = event.get("group");
                            String Date1 = event.get("DATE1");
                            String Date2 = event.get("DATE2");
     
                            JSONObject dump = new JSONObject();
                             
                            dump.put("group", group);
                            dump.put("DATE1", Date1);
                            dump.put("DATE2", Date2);
                             
                            arrays.add(dump);
     
                        }
                    }
                }
                 
                 
     
                JSONObject data = new JSONObject();
                data.put("data", arrays);
     
                json = data.toJSONString();
     
                multiResultsReaderDomain.close();
                resp.getWriter().write(json);
     
            } catch (final IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
     
        }
     
    }


    How can I solve the problem??

    Thanks in advance!
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 07 Sep 2015 Link to this post

    Hello Janice,

    Thanks for posting to the Telerik Developer Forums.

    This error usually occurs at the time of binding a widget to its data source. The reason for this usually is that the data source do not represent an array of data items, which is mandatory for the data binding to succeed.

    For example, in your data source configuration, the response need to return a JSON-formatted object where the key Compliance_Check contains an array of items.

    You need to check this and realign the data source and your service to each other.

    Let me know if you have questions.

    Regards,
    Anton Dobrev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top