# How to add zCalendar events on startup through java code.

willkara
1

So I have successfully implemented a basic calendar object in a Java WebApp. What my plan is, is to take some other data from an outside source and populate the calendar with those events.

So what I need to do is populate the calendar with event data on server startup. I want to be able to do this through all Java code. I used the ZKCalendarEssentials walkthrough to set it up.

Once I am able to add events on server startup through Java, I'll be in the clear. I am using tomcat 7 as my server.

I had to put this as an edit because there is not 'comments' field under an answer. So far, I am just trying to get a simple Proof of Concept working so no MVC or MVVM yet. What my goal is, I want to be able to make a class that extends the ContextListener for Java/Tomcat so that it runs on startup and loads up the event data. After that, the calendar would add this data on its own startup.

^This is what I found for some ideas^

Would you be able to give me an example of setting up the MVC or MVVM for the calendar? It is simple enough for me to configure the code to run on Tomcat Startup, but I am stuck on adding events to the calendar when the page loads through Java. Thanks!

delete retag edit

Sort by » oldest newest most voted

chillworld
5357 4 9
https://github.com/chillw...

First of all, do you use MVC or MVVM?

In(MVC) your controller you extend SelectorComposer<component>, so override the following and put your events there in your calendar.

@Override
public final void doAfterCompose(Component comp) throws Exception {
}


This is from an previous project of me in mvc :

 /**
* After composing the page, the calendar and customerlist are initialised.
* In the calendar we put a model calendarModel with all the values of the
* deliveries that are already plannified. The two list are initialised with
* deliveries that has to be planified and the deliveries that are marked as
* selfservice.
*
* @param comp initial component
* @throws Exception can throw an exception
*/
@Override
public final void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
initCalendarModel();
calendars.setModel(calendarModel);
initCustomerList();
calendars.setContext(deletePopup);
}

/**
* initiate the model of the calendar.
*/
private void initCalendarModel() {
calendarModel = new SimpleCalendarModel();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
}

/**
* creates the content of the calendar event.
*
* @param beginDate date of the event
*/
for (Delivery delivery : deliveryService.getDeliveryPlanningForMonth(beginDate)) {
CalendarEvent ce = PlanningUtil.createEvent(delivery);
}
}


I hope this helps you.

Greetz Chill.

[hide preview]