0

I'm working in a project with Kendo UI HTML5 in the client side and in the server side with Java, WildFly 8.2.0.Final and RESTEasy.

Well my server works fine, however I'll put my code here:

import ec.com.decision.consultas.dao.AccesoesFacade;
import javax.ejb.EJB;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/accesos")
public class AccesoServicio {

    @EJB
    private AccesoesFacade accesoFacade;

    @GET
    @Path("todos")
    @Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
    public Response obtenerTodos() {
        try {

            return Response.ok(accesoFacade.findAll()).build();
        } catch (Exception e) {
            return null;
        }
    }
}

I have the CORSFilter too:

@Provider
public class CORSFilter implements ContainerResponseFilter {

   @Override
   public void filter(final ContainerRequestContext requestContext,
                      final ContainerResponseContext cres) throws IOException {
      cres.getHeaders().add("Access-Control-Allow-Origin", "*");
      cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
      cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
      cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
      cres.getHeaders().add("Access-Control-Max-Age", "1209600");
   }

}

The result is:

    [{
    "accesoesID": 1,
    "nombreAcceso": "Seguridad",
    "controladorAcceso": "S/N",
    "accionAcceso": "Index",
    "idacceso": null,
    "parentAcceso": "_parent",
    "fecCreaAcceso": 1323804595183,
    "estadoAcceso": true,
    "visibleAcceso": true
}, {
    "accesoesID": 2,
    "nombreAcceso": "Accesos",
    "controladorAcceso": "Acceso",
    "accionAcceso": "Index",
    "idacceso": 1,
    "parentAcceso": "_parent",
    "fecCreaAcceso": 1323804595183,
    "estadoAcceso": true,
    "visibleAcceso": true
}, {
    "accesoesID": 3,
    "nombreAcceso": "Roles",
    "controladorAcceso": "Rol",
    "accionAcceso": "Index",
    "idacceso": 1,
    "parentAcceso": "_parent",
    "fecCreaAcceso": 1323804595183,
    "estadoAcceso": true,
    "visibleAcceso": true
}]

And this is my client side code:

<!DOCTYPE html>
<html>
<head lang="es">

    <meta charset="UTF-8">
    <title>Accesos</title>
    <link rel="stylesheet" href="estilos/kendo.common.min.css" />
    <link rel="stylesheet" href="estilos/kendo.material.min.css" />

    <script src="scripts/jquery.min.js"></script>
    <script src="scripts/kendo.all.min.js"></script>
</head>
<body>
    <div id="ejemplo">
        <div id="tbAccesos"></div>

        <script>

            $(document).ready(function() { 

               $("#tbAccesos").kendoGrid({
                    dataSource: {

                        transport: {

                            read: {
                                url: function (data) {
                                    return "http://localhost:8080/Consultas-1.0/rest/accesos/todos";
                                },
                                contentType: "application/json; charset=utf-8",
                                type: 'GET',
                                dataType: "jsonp"
                            }
                        },
                        schema: {
                            model: {
                                id:"accesoesID",
                                fields: {
                                    accesoesID: { type: "number" },
                                    nombreAcceso: { type: "string" },
                                    controladorAcceso: { type: "string" },
                                    accionAcceso: { type: "string" },
                                    parentAcceso: { type: "string" },
                                    fecCreaAcceso: { type: "date" },
                                    estadoAcceso: { type: "boolean" },
                                    visibleAcceso: { type: "boolean" }
                                }
                            }
                        },
                        pageSize: 20,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    height: 550,
                    groupable: true,
                    filterable: true,
                    sortable: true,
                    pageable: true,
                    columns: [{
                        field:"accesoesID",
                        filterable: false,
                        hidden: true
                    },
                        {
                            field: "nombreAcceso",
                            title: "Nombre"
                        }, {
                            field: "controladorAcceso",
                            title: "Controlador"
                        }, {
                            field: "accionAcceso",
                            title: "Accion"
                        }, {
                            field: "parentAcceso",
                            title: "Acceso padre"
                        }, {
                            field: "fecCreaAcceso",
                            title: "Fecha de creación",
                            format: "{0:MM/dd/yyyy}"
                        }, {
                            field: "estadoAcceso",
                            title: "Estado"
                        }, {
                            field: "visibleAcceso",
                            title: "Visible"
                        }
                    ]
                });
            });
        </script>


    </div>
</body>
</html>

When I run the client code, only appear the headers of the kendo grid, but no data. Any ideas? or I'm doing something wrong?

Alex
  • 45
  • 3
  • 8

1 Answers1

0

Because you are using server paging, you need to define in schema total and data mappings from service. this is the structure expected when server paging is set to true. { Total : 30, Data : [array of data]

}

Ajay Kumar
  • 2,031
  • 2
  • 13
  • 17
  • In the model of my schema I need to put all the fields of the JSON result from the server? – Alex Jul 24 '15 at 17:21
  • try setting server paging sorting to false, when they are set to true, then api expects a bit different structure of data – Ajay Kumar Jul 24 '15 at 17:37