我已经实现了fullCalendar,并且事件也从数据库中显示出来。 我想为另一个假期表做同样的事情。 我在这里发布我的代码。
package net.admin.module.view;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import org.json.JSONArray;
import org.json.JSONObject;
import net.admin.module.controller.EventManager;
import net.admin.module.controller.HolidaysManager;
import net.admin.module.model.Event;
import net.admin.module.model.Holidays;
import com.opensymphony.xwork2.ActionSupport;
public class EventAction extends ActionSupport {
private static final long serialVersionUID = 9149826260758390091L;
private Event event;
private List<Event> eventList;
private int id;
private Holidays holidays;
private List<Holidays> holidaysList;
private HolidaysManager holidaysManager;
private EventManager eventManager;
public EventAction() {
eventManager = new EventManager();
}
public String execute() {
this.eventList = eventManager.list();
System.out.println("execute called");
return SUCCESS;
}
public String eventAjax() {
this.eventList = eventManager.list();
// this.holidaysList = holidaysManager.list();
HttpServletRequest request = ServletActionContext.getRequest();
JSONObject json = new JSONObject();
JSONArray jArr = new JSONArray();
try{
JSONObject jObject = null;
Event event = null;
for(int i = 0; i < eventList.size(); i++) {
event = eventList.get(i);
jObject=new JSONObject();
jObject.put("title", event.getName());
jObject.put("start", event.getDate());
jObject.put("allDay", true);
// jObject.put("end", event.getDate());
jArr.put(jObject);
}
json.put("eventdata", jArr);
request.setAttribute("json", jArr);
}
catch(Exception e){
e.printStackTrace();
}
return "json";
}
public String addEvent() {
System.out.println(getEvent());
try {
Event eve = getEvent();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
eve.setDate(df.parse(eve.getDateStr()));
} catch (ParseException e) {
e.printStackTrace();
}
eventManager.addEvent(eve);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
public String delete() {
eventManager.deleteEvent(getId());
return SUCCESS;
}
public Event getEvent() {
return event;
}
public List<Event> getEventList() {
return eventList;
}
public void setEvent(Event event) {
this.event = event;
}
public void setEventList(List<Event> eventList) {
this.eventList = eventList;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Holidays getHolidays() {
return holidays;
}
public List<Holidays> getHolidaysList() {
return holidaysList;
}
public void setHolidays(Holidays holidays) {
this.holidays = holidays;
}
public void setHolidaysList(List<Holidays> holidaysList) {
this.holidaysList = holidaysList;
}
public HolidaysManager getHolidaysManager() {
return holidaysManager;
}
public void setHolidaysManager(HolidaysManager holidaysManager) {
this.holidaysManager = holidaysManager;
}
}
这是我的动作类。
<!DOCTYPE html>
<html>
<head>
<link href='css/fullcalendar.css' rel='stylesheet' />
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='js/jquery.min.js'></script>
<script src='js/jquery-ui.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<link href="jquery-ui-1.10.0.custom.css" rel="stylesheet" type="text/css" media = "all"/>
<link rel='stylesheet' type='text/css' href='cssdata/fullcalendar.css' />
<script src="js/jquery-1.9.0.js"></script>
<script src="js/jquery-ui-1.10.0.custom.min.js"></script>
<script type='text/javascript' src='js/fullcalendar.js'></script>
<pre>
<script>
var eventData = [];
$(document).ready(function() {
//getEvents();
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
editable: true,
events: function(start, end, callback) {
$.ajax({
url: 'eventAjax.action',
dataType: 'json',
data: {
// our hypothetical feed requires UNIX timestamps
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000)
},
success: function(doc) {
var events = [];
$(doc).each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start') // will be parsed
});
});
callback(events);
}
});
}
});
});
/* function getEvents(){
$.post("eventAjax.action", {},
function(data){
eventData=data;
alert(eventData);
});
} */
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
这是我的jsp。 日历显示截至目前数据库中存在的所有事件。我想对我的假期表做同样的事情。
答案 0 :(得分:1)
您可以创建另一个操作类,并将多个event sources添加到完整日历中,如下所示
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
url: '/myfeed.php',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
// any other sources...
]
});