0

I've tried using the primefaces' schedule component, and I can navigate when an event is clicked by using this:

XHTML:

<p:schedule id="schedule" value="#{myControllerBean.eventModel}">
    <p:ajax event="eventSelect" listener="#{pmyControllerBean.onEventSelect}"/>
</p:schedule>

Java:

import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.DefaultScheduleEvent;
import org.primefaces.model.LazyScheduleModel;
import org.primefaces.model.ScheduleModel;

public void onEventSelect(SelectEvent selectEvent) {
    ConfigurableNavigationHandler cnh =
        (ConfigurableNavigationHandler)FacesContext.
            getCurrentInstance().getApplication().getNavigationHandler();

    cnh.performNavigation("myPage?faces-redirect=true");
}

My problem is that myPage should actually be returned by a method called from another controller bean, which takes a parameter (think details page for an entity):

@Named
@RequestScoped
public class EntityDetails {
    private MyEntity entity;

    public String getDetail(MyEntity entity) {
        this.entity = entity;
        return "myPage";
    }
}

I also know how to retrieve the MyEntity object from the event (I've extended DefaultScheduleEvent to contain it) in onEventSelect, so it looks like this at this point:

public void onEventSelect(SelectEvent selectEvent) {
    ConfigurableNavigationHandler cnh =
        (ConfigurableNavigationHandler)FacesContext.
            getCurrentInstance().getApplication().getNavigationHandler();

    MyEntity entity = ((MyEntityEvent)selectEvent.getObject()).getEntity()

    cnh.performNavigation("MyPage?faces-redirect=true");
}

My question is: how can I call and redirect to EntityDetail.getDetails(entity) in onEventSelect?

Update: So ok, you can use the method directly. But I now have another problem: if I keep the "?faces-redirect=true", my detail page shows no data from my entity at all. If I remove it, I get the correct data, but the next navigation (any navigation) leads to the detail page again, but this time with no data again.

@Inject EntityDetails entityDetail;
...
cnh.performNavigation(entityDetails.getDetail(entity) + "?faces-redirect=true"); //no data in the page
cnh.performNavigation(entityDetails.getDetail(entity)); //data present, but the next navigation leads to the details page with no data
Kilazur
  • 3,089
  • 1
  • 22
  • 48

0 Answers0