Displaying Calendar Items"

From Documentation
Line 8: Line 8:
 
* <tt>ContentRenderer</tt> (View): renders a calender-related data to the client-side upon <tt>CalendarModel</tt>
 
* <tt>ContentRenderer</tt> (View): renders a calender-related data to the client-side upon <tt>CalendarModel</tt>
  
Base on this architecture, if you want to show some items on a Calendar, you need to create some <tt>CalendarItem</tt> in a <tt>CalendarModel</tt> and assign it to <tt>Calendars</tt>.
+
 
  
 
= Create a CalendarModel =
 
= Create a CalendarModel =
For most cases, the default implementation, SimpleCalendarModel, is enough.
+
Base on this architecture, if you want to show some items on a Calendar, you need to create some <tt>CalendarItem</tt> in a <tt>CalendarModel</tt> and assign it to <tt>Calendars</tt>. The default implementation, DefaultCalendarItem and SimpleCalendarModel, are sufficient for most requirements.
 +
 
 +
You can instantiate a <tt>SimpleCalendarModel</tt> with a collection of <tt>DefaultCalendarItem</tt> or add a <tt>DefaultCalendarItem</tt> after instantiation.
 +
 
 +
<source lang='java'>
 +
private SimpleCalendarModel model;
 +
...
 +
    model = new SimpleCalendarModel(CalendarItemGenerator.generateList());
 +
    DefaultCalendarItem calendarItem = new DefaultCalendarItem("my title",
 +
                "my content",
 +
                null,
 +
                null,
 +
                false,
 +
                LocalDateTime.now().truncatedTo(ChronoUnit.HOURS),
 +
                LocalDateTime.now().truncatedTo(ChronoUnit.HOURS).plusHours(2)
 +
    model.add(calendarItem);
 +
</source>
  
 
= Assign the Model to Calendars=
 
= Assign the Model to Calendars=

Revision as of 06:43, 20 January 2021


DocumentationZK Calendar EssentialsDisplaying Calendar Items
Displaying Calendar Items



Component in MVC Pattern

In the component perspective, Calendars is designed in MVC pattern:

  • Calendars (Controller): receive UI events, calling event listeners
  • CalendarModel (Model): stores CalendarItem
  • ContentRenderer (View): renders a calender-related data to the client-side upon CalendarModel


Create a CalendarModel

Base on this architecture, if you want to show some items on a Calendar, you need to create some CalendarItem in a CalendarModel and assign it to Calendars. The default implementation, DefaultCalendarItem and SimpleCalendarModel, are sufficient for most requirements.

You can instantiate a SimpleCalendarModel with a collection of DefaultCalendarItem or add a DefaultCalendarItem after instantiation.

private SimpleCalendarModel model;
...
    model = new SimpleCalendarModel(CalendarItemGenerator.generateList());
    DefaultCalendarItem calendarItem = new DefaultCalendarItem("my title",
                "my content",
                null,
                null,
                false,
                LocalDateTime.now().truncatedTo(ChronoUnit.HOURS),
                LocalDateTime.now().truncatedTo(ChronoUnit.HOURS).plusHours(2)
    model.add(calendarItem);

Assign the Model to Calendars

The example project is at Github


Last Update : 2021/01/20

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.