Java FullCalendar-添加多个事件或添加事件源

Java FullCalendar-添加多个事件或添加事件源,java,jquery,fullcalendar,Java,Jquery,Fullcalendar,我已经浏览了stackoverflow中的帖子,将事件添加到FullCalendar中,但是我确实是个新手,如果没有一个例子,我会发现很难理解。简言之,这里有没有人能帮我把它哑下来,以便在FullCalendar中添加一个对象数组 我想添加我创建的约会(日期、字符串名称、字符串电话号码)。因此,它们将在列表中检索: PersistenceManager pm = PMF.get().getPersistenceManager(); String query = "select from "

我已经浏览了stackoverflow中的帖子,将事件添加到FullCalendar中,但是我确实是个新手,如果没有一个例子,我会发现很难理解。简言之,这里有没有人能帮我把它哑下来,以便在FullCalendar中添加一个对象数组

我想添加我创建的约会(日期、字符串名称、字符串电话号码)。因此,它们将在列表中检索:

 PersistenceManager pm = PMF.get().getPersistenceManager();
 String query = "select from " + Appointment.class.getName();  
 query += " where merchant == '" + session.getAttribute("merchant") + "'";
 List<Appointment> appointment = (List<Appointment>) pm.newQuery(query).execute();
PersistenceManager pm=PMF.get().getPersistenceManager();
String query=“从”+约会.class.getName()中选择”;
查询+=“其中商户==”+session.getAttribute(“商户”)+“;
列表约会=(列表)pm.newQuery(query.execute();
如何用我获得的列表填充FullCalendar插件?非常感谢

看一看 这是在rails中完成的,但我认为您需要的是

dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
},
完整jquery

$('#calendar').fullCalendar({
        dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
        },
          header: {
              left: 'prev,today,next',
              center: 'title',
              right: 'month,agendaWeek,agendaDay'
          },
          selectable: true,
          selectHelper: true,
          editable: false,
          ignoreTimezone: false,
          select: this.select,
          eventClick: this.eventClick,
          eventDrop: this.eventDropOrResize,
          eventSources: [
            {
                url: '/event_instances.json',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                },
                error: function() {
                    alert('there was an error while fetching events!');
                }
            }
          ],

          eventResize: this.eventDropOrResize
      });
看看 这是在rails中完成的,但我认为您需要的是

dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
},
完整jquery

$('#calendar').fullCalendar({
        dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
        },
          header: {
              left: 'prev,today,next',
              center: 'title',
              right: 'month,agendaWeek,agendaDay'
          },
          selectable: true,
          selectHelper: true,
          editable: false,
          ignoreTimezone: false,
          select: this.select,
          eventClick: this.eventClick,
          eventDrop: this.eventDropOrResize,
          eventSources: [
            {
                url: '/event_instances.json',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                },
                error: function() {
                    alert('there was an error while fetching events!');
                }
            }
          ],

          eventResize: this.eventDropOrResize
      });

Melvin如果在堆栈中有示例的音调,请尝试搜索添加事件源

根据我在imfullcalendar上的经验,您可以通过JSON、格式良好的XML和数组添加事件,我想就是这样。您可以使用ajax调用来检索3种格式


在服务器端,您应该创建一个方法来返回已构建XML/JSON/数组的字符串,以便将ajax调用传递给您。

Melvin如果堆栈中有示例,请尝试搜索添加事件源

根据我在imfullcalendar上的经验,您可以通过JSON、格式良好的XML和数组添加事件,我想就是这样。您可以使用ajax调用来检索3种格式


在服务器端,您应该创建一个方法来返回已构建XML/JSON/数组的字符串,以便将ajax调用传递给您。

如果有人遇到与我相同的问题-您有一个java对象列表,并希望它填充FullCalendar,以下是解决方案:

JSP页面

$(document).ready(function() {

            var calendar = $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                        },
                    selectable: true,
                    selectHelper: true,

                select: function(start, end, allDay) {
                        var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                end: end,
                                allDay: allDay
                            },
                            true // make the event "stick"
                            );
                            }
                            calendar.fullCalendar('unselect');
                        },
                                editable: true,

                                eventSources: [
                                    {
                                            url: '/calendarDetails',
                                            type: 'GET',
                                            data: {
                                                start: 'start',
                                                end: 'end',
                                                id: 'id',
                                                title: 'title',
                                                allDay: 'allDay'
                                            },
                                            error: function () {
                                                alert('there was an error while fetching events!');
                                            }
                                    }
                            ]         
                    });
            });
请不要使用URL,它是servlet URL

Servlet

    public class CalendarServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

        String something = req.getSession().getAttribute("merchant").toString(); //get info from your page (e.g. name) to search in query for database

        //Get the entire list of appointments available for specific merchant from database

        //Convert appointment to FullCalendar (A class I created to facilitate the JSON)
        List<FullCalendar> fullCalendar = new ArrayList<FullCalendar>();
        for (Appointment a : appointment) {
            String startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(a.getDate());
            startDate = startDate.replace(" ", "T");

            //Calculate End Time
            Calendar c = Calendar.getInstance();
            c.setTime(a.getDate());
            c.add(Calendar.MINUTE, 60);
            String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
            endDate = endDate.replace(" ", "T");

            FullCalendar fc = new FullCalendar(startDate, endDate, a.getId(), a.getName() + " @ " + a.getPhone(), false);
            fullCalendar.add(fc);
        }

        //Convert FullCalendar from Java to JSON
        Gson gson = new Gson();
        String jsonAppointment = gson.toJson(fullCalendar);

        //Printout the JSON
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        try {
            resp.getWriter().write(jsonAppointment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
公共类CalendarServlet扩展了HttpServlet{ 公共无效数据集(HttpServletRequest请求、HttpServletResponse响应) 抛出IOException{ String something=req.getSession().getAttribute(“商家”).toString();//从页面获取信息(例如名称)以在查询中搜索数据库 //从数据库中获取特定商户的完整预约列表 //将约会转换为FullCalendar(我创建了一个类来简化JSON) List fullCalendar=new ArrayList(); 预约(a:预约){ 字符串startDate=新的SimpleDateFormat(“yyyy-MM-dd HH:MM:ss”).format(a.getDate()); 开始日期=开始日期。替换(“,”T”); //计算结束时间 Calendar c=Calendar.getInstance(); c、 设置时间(a.getDate()); c、 添加(日历分钟,60); 字符串endDate=newsimpledateformat(“yyyy-MM-dd HH:MM:ss”).format(c.getTime()); endDate=endDate.replace(“,“T”); FullCalendar fc=新的FullCalendar(开始日期、结束日期、a.getId()、a.getName()+“@”+a.getPhone()、false); fullCalendar.add(fc); } //将FullCalendar从Java转换为JSON Gson Gson=新的Gson(); 字符串jsonappoint=gson.toJson(fullCalendar); //打印出JSON 分别为setContentType(“应用程序/json”); 分别为setCharacterEncoding(“UTF-8”); 试一试{ resp.getWriter()write(jsonappoint); }捕获(IOE异常){ e、 printStackTrace(); } } }
如果您需要有关JSON或GSON的更多信息,请查看上面的注释。

如果有人遇到与我相同的问题-您有一个java对象列表,并希望它填充FullCalendar,以下是解决方案:

JSP页面

$(document).ready(function() {

            var calendar = $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                        },
                    selectable: true,
                    selectHelper: true,

                select: function(start, end, allDay) {
                        var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                end: end,
                                allDay: allDay
                            },
                            true // make the event "stick"
                            );
                            }
                            calendar.fullCalendar('unselect');
                        },
                                editable: true,

                                eventSources: [
                                    {
                                            url: '/calendarDetails',
                                            type: 'GET',
                                            data: {
                                                start: 'start',
                                                end: 'end',
                                                id: 'id',
                                                title: 'title',
                                                allDay: 'allDay'
                                            },
                                            error: function () {
                                                alert('there was an error while fetching events!');
                                            }
                                    }
                            ]         
                    });
            });
请不要使用URL,它是servlet URL

Servlet

    public class CalendarServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

        String something = req.getSession().getAttribute("merchant").toString(); //get info from your page (e.g. name) to search in query for database

        //Get the entire list of appointments available for specific merchant from database

        //Convert appointment to FullCalendar (A class I created to facilitate the JSON)
        List<FullCalendar> fullCalendar = new ArrayList<FullCalendar>();
        for (Appointment a : appointment) {
            String startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(a.getDate());
            startDate = startDate.replace(" ", "T");

            //Calculate End Time
            Calendar c = Calendar.getInstance();
            c.setTime(a.getDate());
            c.add(Calendar.MINUTE, 60);
            String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
            endDate = endDate.replace(" ", "T");

            FullCalendar fc = new FullCalendar(startDate, endDate, a.getId(), a.getName() + " @ " + a.getPhone(), false);
            fullCalendar.add(fc);
        }

        //Convert FullCalendar from Java to JSON
        Gson gson = new Gson();
        String jsonAppointment = gson.toJson(fullCalendar);

        //Printout the JSON
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        try {
            resp.getWriter().write(jsonAppointment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
公共类CalendarServlet扩展了HttpServlet{ 公共无效数据集(HttpServletRequest请求、HttpServletResponse响应) 抛出IOException{ String something=req.getSession().getAttribute(“商家”).toString();//从页面获取信息(例如名称)以在查询中搜索数据库 //从数据库中获取特定商户的完整预约列表 //将约会转换为FullCalendar(我创建了一个类来简化JSON) List fullCalendar=new ArrayList(); 预约(a:预约){ 字符串startDate=新的SimpleDateFormat(“yyyy-MM-dd HH:MM:ss”).format(a.getDate()); 开始日期=开始日期。替换(“,”T”); //计算结束时间 Calendar c=Calendar.getInstance(); c、 设置时间(a.getDate()); c、 添加(日历分钟,60); 字符串endDate=newsimpledateformat(“yyyy-MM-dd HH:MM:ss”).format(c.getTime()); endDate=endDate.replace(“,“T”); FullCalendar fc=新的FullCalendar(开始日期、结束日期、a.getId()、a.getName()+“@”+a.getPhone()、false); fullCalendar.add(fc); } //将FullCalendar从Java转换为JSON Gson Gson=新的Gson(); 字符串jsonappoint=gson.toJson(fullCalendar); //打印出JSON 分别为setContentType(“应用程序/json”); 分别为setCharacterEncoding(“UTF-8”); 试一试{ resp.getWriter()write(jsonappoint); }捕获(IOE异常){ e、 printStackTrace(); } } }
如果您需要有关JSON或GSON的更多信息,请查看上面的注释。

我也查看了,但没有解决我的问题。好吧,如果有人也想知道,您可以从列表中将它们转换为JSON objec