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?– Renan Gomes
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.
– Douglas Emerick
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 archiveWposExibeCalendario
.– Bruno César
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.
– Douglas Emerick