问题
I have added PrimeFaces schedule from this page and got the results like the following:
I got the following events working fine but how do I get and handle events when prev
or next
is clicked?
I have also highlighted some more in the image:
<p:ajax event="dateSelect" listener="#{scheduleJava8View.onDateSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" />
<p:ajax event="eventSelect" listener="#{scheduleJava8View.onEventSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" />
<p:ajax event="eventMove" listener="#{scheduleJava8View.onEventMove}" update="messages" />
<p:ajax event="eventResize" listener="#{scheduleJava8View.onEventResize}" update="messages" />
回答1:
To capture dates / view changes on the server / in your bean, I found it easiest to just go for lazy loading (showcase, documentation). This will basically allow you to have a method in the bean where the start and end date are passed in case the view changes:
lazyModel = new LazyScheduleModel() {
@Override
public void loadEvents(LocalDateTime start, LocalDateTime end) {
//
}
};
.. and as a bonus, your events will be lazily loaded!
Note that the type of dates (java.time.LocalDateTime
or java.util.Date
) will depend on the PrimeFaces version. See the migration guide.
To modify the UI, you need to know that PrimeFaces is using FullCalendar for the p:schedule
component. You can use the extender attribute and configure the FullCalendar to your needs. See the toolbar documentation. Note that the version of FullCalendar will depend on the PrimeFaces version. Again, see the migration guide.
To set the time format, use the timeFormat
attribute. It uses Moment.js. You could use hh:mmA
. Try it on https://www.primefaces.org/showcase/ui/data/schedule/configureable.xhtml
来源:https://stackoverflow.com/questions/61004498/how-to-get-the-event-when-prev-next-are-clicked-schedule-with-primefaces