Search code examples
jsfjsf-2managed-beansession-scopesetpropertyactionlistener

JSF page does not retrieve variable value from a managed bean's field


I have the following JSF page.

enter image description here

The "Manage Attendee" link is defined by the following XHTML:

<h:form>
    <h:commandLink value="Manage Attendees" action="/Management/Event/manageAttendees?faces-redirect=true">
    <f:setPropertyActionListener target="#{managerManager.currentEvent}" value="#{event}" />
    </h:commandLink>
    &nbsp;
    (...)
</h:form>

currentEvent is a field in the "ManagerManager" ManagedBean which is set upon the redirect and refers to the event in the description field. It has a list which we want to iterate through. However, the second page:

enter image description here

Does not render the attributes. Like the currentEvent list was empty, which the debug report says it's not. The following is the code for the second page which should get the title:

<h2>Attendees in this Event</h2>
    <h:dataTable
        var="attendees"
        summary="List of attendees in this event."
        value="#{managerManager.currentEvent.attendees}"
        rules="all"
        cellpadding="5">

        <h:column>
            <f:facet name="header">
                <h:outputText value="Name" />
            </f:facet>
            <h:outputText value="#{attendees.attendee.name}" />
        </h:column>
    </h:dataTable>

The ManagedBean is session scoped as well. It looks like the second page doesn't have access to currentEvent... why?


Solution

  • Turns out it as an import statement error.
    The @SessionScoped annotation being used in the Managed Bean was from
    import javax.enterprise.context.SessionScoped;
    rather than
    import javax.faces.bean.SessionScoped;
    as it obviously should be. Which explains why only this specific page had this issue in my project.