Displaying Calendar Items"
From Documentation
Line 13: | Line 13: | ||
{{versionSince| 3.0.0}} | {{versionSince| 3.0.0}} | ||
− | Base on | + | Base on the above architecture, if you want to show some items on a Calendar, you need to create some <tt>CalendarItem</tt> objects, put them into a <tt>CalendarModel</tt>, and assign the model to <tt>Calendars</tt>. The default implementation, <tt>DefaultCalendarItem</tt> and <tt>SimpleCalendarModel</tt>, 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. | You can instantiate a <tt>SimpleCalendarModel</tt> with a collection of <tt>DefaultCalendarItem</tt> or add a <tt>DefaultCalendarItem</tt> after instantiation. |
Revision as of 07:14, 20 January 2021
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
Since 3.0.0
Base on the above architecture, if you want to show some items on a Calendar, you need to create some CalendarItem objects, put them into a CalendarModel, and assign the model 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
After creating a SimpleCalendarModel, we need to associate a component with the model, so that Calendar will render items to a browser.
public class DisplayComposer extends SelectorComposer {
@Wire("calendars")
private Calendars calendars;
private SimpleCalendarModel model;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
initModel();
calendars.setModel(model);
}
The example project is at Github