java - Match sql date to fullcalendar for displaying -
i'm new fullcalendar , don't know how adapt according project requirements. chose because lecturer wants me to. aware fullcalendar drag , drop function. i'm trying have add button each cell in fullcalendar page when click add go jsp page (add events). have date inputs (java.sql.date) dates must match full calendar date.i'm sure it's logic here in index.jsp needs done if , else statement. if mysql date match fullcalendar date,you display in cell. it's doing print out date in every cell database.and need display title. refer pictures attached :)
retrieveservlet: retrieve addeventsservlet (for adding events) ackage servlet; import java.io.ioexception; import java.util.arraylist; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import database.dbao; import model.addevents; /** * servlet implementation class retrieveservlet */ @webservlet("/retrieveservlet") public class retrieveservlet extends httpservlet { private static final long serialversionuid = 1l; /** * @see httpservlet#httpservlet() */ public retrieveservlet() { super(); // todo auto-generated constructor stub } /** * @see httpservlet#doget(httpservletrequest request, httpservletresponse response) */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub //response.getwriter().append("served at: ").append(request.getcontextpath()); dopost(request,response); //dispatcher sents deget request, since ur code in dopost, u need it. } /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { try { dbao mydatabase = new dbao(); arraylist <addevents> myeventlist = mydatabase.getaddevents(); system.out.println(myeventlist.size()); request.setattribute("eventlist",myeventlist); request.getrequestdispatcher("index.jsp").forward(request, response); }catch(exception ex) { system.out.println("error accessing database:" +ex.getmessage()); } } } addeventsservlet: package servlet; import java.io.ioexception; import java.text.dateformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.arraylist; import java.util.date; import java.util.listiterator; import javax.servlet.requestdispatcher; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import database.dbao; import model.addevents; /** * servlet implementation class addeventsservlet */ @webservlet("/addeventsservlet") public class addeventsservlet extends httpservlet { private static final long serialversionuid = 1l; /** * @see httpservlet#httpservlet() */ public addeventsservlet() { super(); // todo auto-generated constructor stub } /** * @see httpservlet#doget(httpservletrequest request, httpservletresponse response) */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub //response.getwriter().append("served at: ").append(request.getcontextpath()); } /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub //doget(request, response); addevents myevent = new addevents(); //create object based on java class customers //dateformat sdf = new simpledateformat("mm/dd/yyyy"); //assignment of data myevent.settitle(request.getparameter("title")); myevent.seteventdesc(request.getparameter("eventdesc")); myevent.setstarttime(request.getparameter("starttime")); myevent.setendtime(request.getparameter("endtime")); myevent.setbudget(double.valueof(request.getparameter("budget"))); myevent.setstartdate(java.sql.date.valueof(request.getparameter("startdate"))); myevent.setenddate(java.sql.date.valueof(request.getparameter("enddate"))); myevent.setenvironment(request.getparameter("environment")); system.out.println(request.getparameter("title")); system.out.println(request.getparameter("eventdesc")); system.out.println(request.getparameter("starttime")); system.out.println(request.getparameter("endtime")); system.out.println(request.getparameter("budget")); system.out.println(request.getparameter("startdate")); system.out.println(request.getparameter("enddate")); system.out.println(request.getparameter("environment")); system.out.println("title="+myevent.gettitle()); system.out.println("eventdesc="+myevent.geteventdesc()); system.out.println("starttime="+myevent.getstarttime()); system.out.println("endtime="+myevent.getendtime()); system.out.println("budget="+myevent.getbudget()); system.out.println("startdate="+myevent.getstartdate()); system.out.println("enddate="+myevent.getenddate()); system.out.println("environment="+myevent.getenvironment()); try { dbao mydatabase = new dbao(); arraylist <addevents> myeventlist = mydatabase.getaddevents(); //not needed //addevents myeventdetails =mydatabase.isevent(myevent,title, eventdesc, starttime, endtime, budget); //not needed httpsession myrequest = request.getsession(true); //not needed request.setattribute("eventlist",myeventlist); //not needed system.out.println(myeventlist.size()); //not needed // comment out method insert data database mydatabase.addevents(myevent); // dispatcher can go retrieveservlet , let handle retrieve //mydatabase.delete(myevent,title,eventdesc,starttime,endtime,budget,startdate,enddate); //name of delete database request.getrequestdispatcher("index.jsp").forward(request, response); }catch(exception ex) { system.out.println("error accessing database:" +ex); } } } index.jsp: displaying full calendar <%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <%@page import="model.addevents,java.util.arraylist,java.util.listiterator" %> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> <script type="text/javascript" src= "https://code.jquery.com/jquery-3.2.1.min.js"> $(document).ready(function() { var date = new date(); var d = date.getdate(); var m = date.getmonth(); var y = date.getfullyear(); var events_array = [ { title: 'test1', start: new date(2012, 8, 20), tip: 'personal tip 1'}, { title: 'test2', start: new date(2012, 8, 21), tip: 'personal tip 2'} ]; $('#calendar').fullcalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaweek,agendaday' }, dayclick: function(date, jsevent, view) { alert('clicked on: ' + date.format()); alert('coordinates: ' + jsevent.pagex + ',' + jsevent.pagey); alert('current view: ' + view.name); // change day's background color fun $(this).css('background-color', 'red'); }, selectable: true, events: events_array, eventrender: function(event, element) { element.attr('title', event.tip); }}, $('#datepicker').datepicker({ inline: true, onselect: function(datetext, inst) { var d = new date(datetext); $('#fullcalendar').fullcalendar('gotodate', d); } })); function changedate() { var startdate = $('#datepicker').val(); $('#calendar').fullcalendar('gotodate', startdate); } }); </script> <title>calendar</title> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" rel="stylesheet" /> <link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.css" type="text/css" rel="stylesheet" /> </head> <body> <a class= "add_event_label" href="https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea"></a> <div class="container"> <div class="row"> <div class="col-xs-12"> <h1>calendar</h1> <div id="bootstrapmodalfullcalendar"></div> </div> </div> </div> <!-- pop window when press button --> <div id="fullcalmodal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span class="sr-only">close</span></button> <h4 id="modaltitle" class="modal-title"></h4> </div> <div id="modalbody" class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <a class="btn btn-primary" id="eventurl" target="_blank">event page</a> </div> </div> </div> </div> <script src="https://code.jquery.com/jquery.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.2/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script> $(document).ready(function() { $('#bootstrapmodalfullcalendar').fullcalendar({ header: { left: '', center: 'prev title next', right: '' }, //action after calendar loaded eventafterallrender: function(view){ if(view.name == 'month') { //loop .fc-day elements $('.fc-day').each(function(){ //jquery styling $(this).css({ 'font-weight': 'bold', 'font-size': '100%'}); $(this).css('position','relative'); //add elements each .fc-day, can modify content in append() own html button code $(this).append('<a class="add_event_label" onclick="changedate()" href ="addevent.jsp" style="position:absolute;bottom:0;left:0;right:0;display:block;font-size:12px;color:blue;cursor:pointer;">(+)</a>' ); <%!arraylist<addevents> myeventlist; //have declear in declaration tag access in page %> <% myeventlist = (arraylist<addevents>) request.getattribute("eventlist"); if(myeventlist.size() == 0) { %> <h2>no events</h2> <% } else { %> <% listiterator<addevents> li = myeventlist.listiterator(); while(li.hasnext()) { addevents myevent = new addevents(); myevent= (addevents)li.next(); %> //this part should add data according date, it's adding data of title. $(this).append('<p><font size="1">title:</font></p><p><font size="1"><%= myevent.gettitle() %></font></p></p>'); <%} %> <% } %> }); } }, eventclick: function(event, jsevent, view) { //$(".fc-day-number").prepend("(+) "); $('#modaltitle').html(event.title); $('#modalbody').html(event.description); $('#eventurl').attr('href',event.url); $('#fullcalmodal').modal(); return false; } }) }) </script> </body> </html>
Comments
Post a Comment