FullCalendar fill in events by JSON

2

I'm putting the FullCalendar component into my Java application. I'm having trouble loading events into the calendar.

How do I read json from within my js file?

The following is the code below:

JS file:

$.noConflict(); 
jQuery(document).ready(function($) {
    $('#calendar').fullCalendar({
        defaultDate: '2016-02-01',
        editable: true,
        eventLimit: true,
        eventClick: function (calEvent, jsEvent, view) {            
            $("#title").val(calEvent.title);  
            $("#description").val(calEvent.description);
            $("#start").val(calEvent.start);
            Richfaces.showModalPanel('panelCalendar');
        },
        events: "C:/Projetos/Web/ProjetoCalendario/build/web/WEB-INF/classes/wpos/controle/utilidades/WposExibeCalendario",
        eventRender: function(event, element) {
            if(event.type){          
                element.find(".fc-title").prepend("<i class='fa fa-"+event.type+"'></i>");
            }
        }
    });

});

File ExibeCalendario.java :

public class WposExibeCalendario extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List l = new ArrayList();

        CalendarDTO c = new CalendarDTO();
        c.setId(1);
        c.setStart("2016-02-20");
        c.setEnd("2016-02-20");
        c.setTitle("Task in Progress");

        CalendarDTO d = new CalendarDTO();
        d.setId(2);
        d.setStart("2016-02-21");
        d.setEnd("2016-02-21");
        d.setTitle("Task in Progress1");

        l.add(c);
        l.add(d);

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.write(new Gson().toJson(l));
    }
}

File CalendarioDTO.java :

package br.com.advpos.entities;

public class CalendarDTO {

    public int id;
    public String title;
    public String start;
    public String end;
    public String color;

    // getters e setters

}

I am not able to search within my js the class that does the js conversion. Can you help me please?

    
asked by anonymous 11.02.2016 / 18:15

1 answer

1

The error occurred because I did not properly set up the web.xml file.

My file web.xml looks like this:

<servlet>
     <servlet-name>WposExibeCalendario</servlet-name>
     <servlet-class>wpos.controle.utilidades.WposExibeCalendario</servlet-class>
</servlet>
<servlet-mapping>
     <servlet-name>WposExibeCalendario</servlet-name>
     <url-pattern>/WposExibeCalendario</url-pattern>
</servlet-mapping>

And the JS file looked like this:

$.noConflict();
jQuery(document).ready(function($) {

    $('#calendar').fullCalendar({
        defaultDate: '2016-02-01',
        editable: true,
        eventLimit: true,
        eventClick: function (calEvent, jsEvent, view) {            
            $("#title").val(calEvent.title);  
            $("#description").val(calEvent.description);
            $("#start").val(calEvent.start);
            Richfaces.showModalPanel('panelCalendar');
        },
        events: "/Wpos_Advice/WposExibeCalendario",
        eventRender: function(event, element) {
            if(event.type){          
                element.find(".fc-title").prepend("<i class='fa fa-"+event.type+"'></i>");
            }
        }
    });
});

The rest stayed the same. I took this example from the site: link

    
12.02.2016 / 12:40