Fullcalendar fill events by JSON

Asked

Viewed 866 times

2

I’m putting the Fullcalendar component in my Java application. I’m having trouble loading events into the calendar.

How do I read json inside my js file?

Follow 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>");
            }
        }
    });

});

Filing cabinet 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));
    }
}

Filing cabinet 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 unable to search within my js the class that makes js conversion. Can you please help me?

  • events: 'WposExibeCalendario' works?

  • Hello Renan, this way also does not work. Will the problem is in the way or in JS that can not catch the content. I put breakpoint in the Wposexibecalendario class but it doesn’t seem to enter it. I think it should be called even if it is wrong.

  • You want to render the result of GET, JSON serialized with the two tasks, that’s it? Have you ever tried to make a call ajax? I don’t understand why you put the path to the archive WposExibeCalendario.

  • Bruno, I’m implementing now via ajax, but in the Fullcalendar component it already recognizes even if I don’t call by ajax. I posted my answer for better understanding. Thanks for the help.

1 answer

1

The error happened due to me not having properly configured the web.xml file.

My file web.xml was 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 was the same. I took this example from the site: https://mohittare.wordpress.com/2013/07/28/using-fullcalendarwithjava/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.