How to use p:schedule correctly?

I'm trying to create an agenda with jsf. I looked on prime faces' website but I didn't catch how it works, even when I copied the code available on the website. I also made some research here and on google but I found nothing working for me.

So I tried to make the most simple exemple :

In my .xhtml :

<p:schedule value="#{agendaControl.planning}">
        
</p:schedule>

In my .java file :

@Named
@ViewScoped
@Stateful(passivationCapable=true)
public class AgendaControl {
    private ScheduleModel planning;

    @PostConstruct
    public void init() {
        System.out.println("test");
        planning = new DefaultScheduleModel();
    
        DefaultScheduleEvent<?> event = DefaultScheduleEvent.builder()
            .title("test")
            .startDate(LocalDateTime.now())
            .build();
    
        planning.addEvent(event);
    }

    public ScheduleModel getPlanning() {
        return planning;
    }

    public void setPlanning(ScheduleModel planning) {
        this.planning = planning;
    }
}

I would like to know what am I doing wrong and how should I use p:schedule to make it work fine ?

Thank you in advance for your help and any tips. I might have some beginner errors in my code, as I never used jsf before.

EDIT :

I looked on this stackoverflow question, to see if my @PostConstruct annotated method worked, and yes it is. I have my "test" event in my planning variable.


Solution 1:

After a few more researches, I found out how to make it work as I wanted. Here is a sample minimalist code to make your agenda work.

NOTE : the referenced link in the question is about PrimeFaces 11. Here is the link for PrimeFaces 8, version used here. The documentation is a bit clearer than the v11, don't forget to also check it out for other information !

agenda.xhtml :

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:p="http://primefaces.org/ui"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Agenda</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<body>
    <p:growl id="messages" showDetail="true"/>
    
    <p:schedule id="schedule" value="#{agendaControl.eventModel}"></p:schedule>
</body>

AgendaControl.java :

@Named
@ViewScoped // import javax.faces.view.ViewScoped;
public class AgendaControl implements Serializable {
    private ScheduleModel eventModel;

    @PostConstruct
    public void init() {
        eventModel = new DefaultScheduleModel();

        DefaultScheduleEvent<?> event = DefaultScheduleEvent.builder()
            .title("Champions League Match")
            // as I tested, you NEED a start date and enddate
            .startDate(LocalDateTime.now())
            .endDate(LocalDateTime.of(2022, 1, 18, 12, 0)) // change with tomorrow's date
            .build();
        eventModel.addEvent(event);
    }

    public ScheduleModel getEventModel() {
        return eventModel;
    }
}

DO NOT FORGET : you need to add this depedency in your pom.xml (maven project in my case) :

<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>8.0</version>
</dependency>

You won't be able to import the needed classes in your .java file if you forget it.

I hope this will helped you.