I've basically done it. Here is the code
1. Above scheduler put your header with all buttons that you need
Code: Select all
<h:panelGrid columns="3">
<p:commandLink value="Month" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.selectView}" process="@this">
<f:attribute name="view" value="month"/>
</p:commandLink>
<p:commandLink value="Week" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.selectView}" process="@this">
<f:attribute name="view" value="agendaWeek"/>
</p:commandLink>
<p:commandLink value="Day" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.selectView}" process="@this">
<f:attribute name="view" value="agendaDay"/>
</p:commandLink>
<p:commandLink value="Previous" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.nextPrevious}" process="@this">
<f:attribute name="increment" value="previous"/>
</p:commandLink>
<p:commandLink value="Next" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.nextPrevious}" process="@this">
<f:attribute name="increment" value="next"/>
</p:commandLink>
<p:commandLink value="Today" update=":mainForm:schedule:schedule" actionListener="#{calendar.calendarListForm.today}" process="@this"/>
</h:panelGrid>
2. In java bean add these methods and populate initial date (it is the most important thing because lazy model will do all you need for you)
Code: Select all
public void selectView(ActionEvent event){
String view = (String) event.getComponent().getAttributes().get("view");
this.getModel().setView(view);
}
public void nextPrevious(ActionEvent event){
String increment = (String) event.getComponent().getAttributes().get("increment");
int moveValue = increment.equals("next")?1:-1;
Calendar cal = DateUtil.createCalendar(this.getModel().getInitialDate());
if(this.getModel().getView().equals(TxScheduleModel.VIEW_DAY_AGENDA))
cal.add(Calendar.DAY_OF_MONTH, moveValue);
else if(this.getModel().getView().equals(TxScheduleModel.VIEW_WEEK_AGENDA))
cal.add(Calendar.WEEK_OF_MONTH, moveValue);
else if(this.getModel().getView().equals(TxScheduleModel.VIEW_MONTH))
cal.add(Calendar.MONTH, moveValue);
this.getModel().setInitialDate(cal.getTime());
}
public void today(ActionEvent event){
Calendar cal = DateUtil.createCalendar(new Date());
this.getModel().setInitialDate(cal.getTime());
}
3. Make schedule with no header at all
Code: Select all
<p:schedule value="#{cc.attrs.calendarForm.model}" rightHeaderTemplate="none" centerHeaderTemplate="none"
style="width:1000px;" leftHeaderTemplate="none" editable="true" firstHour="#{cc.attrs.calendarForm.model.firstHour}" initialDate="#{cc.attrs.calendarForm.model.initialDate}"
locale="#{userSessionBean.lang.langIso}" minTime="#{cc.attrs.calendarForm.model.minTime}" maxTime="#{cc.attrs.calendarForm.model.maxTime}"
showWeekends="#{cc.attrs.calendarForm.model.showWeekends}" startWeekday="1" view="#{cc.attrs.calendarForm.model.view}" id="schedule">
<p:ajax event="dateSelect" listener="#{cc.attrs.calendarForm.onDateSelect}" update="calendar-view, :mainForm:MainAdminToolbar"/>
<p:ajax event="eventSelect" listener="#{cc.attrs.calendarForm.onEventSelect}" update=":mainForm:MainAdminToolbar" disabled="#{!cc.attrs.disaleUpdateContent}"/>
<p:ajax event="eventSelect" listener="#{cc.attrs.calendarForm.onEventSelect}" update="@form, :mainForm:MainAdminToolbar" disabled="#{cc.attrs.disaleUpdateContent}" />
</p:schedule>
4. In constructor add lazy model
Code: Select all
public AbstractCalendar(CalendarSearch search, TxModuleManagedBean bean){
super(bean);
model = new TxScheduleModel(){
private static final long serialVersionUID = 7003881993658609275L;
@Override
public void loadEvents(Date start, Date end) {
doPaging(start, end);
}
};
}
You could save start and end dates from loadEvents method as local variables and read them for displaying title in header - e.g - 24. Mar - 12. Maj 2012
With this code I don't have different xhtml pages for every view, but just one p:schedule, and I have a possibility to update different components after Prev, Next, Today or Day, Week, Month View is fired
Smithh, thanks again!