Search code examples
javajsf-2managed-bean

xhtml not showing session scoped values


I have a ManagedBean that is Session Scoped that injects another two Session Scoped Beans, they both have their proper getter and setters.

My class is as follows:

@ManagedBean(name="oneClass")
@SessionScoped
public class OneClassController implements Serializable {

    @ManagedProperty(value="#{myOtherBean}")
    public AnotherClass another;

    @ManagedProperty(value="#{requestBean}")
    public RequestClass request;

    public String foo() {
        another = getAnotherService(request);
        return "page?faces-redirect=true";
    }

    //getters and setters for AnotherClass and RequestClass
}

Now, the request class holds all the values for a web service request. Those values are filled within a form in a xhtml page.

When the user finishes filling up the request and fires the action from a button, it enters the foo method. The debug shows the request with the correct data, and when I call it, another gets filled up correctly.

Now, page.xhtml looks like this:

<h:outputText value="#{requestBean.agentId}" />
<h:outputText value="#{myOtherBean.name}" />
<h:outputText value="#{myOtherBean.lastname}" />

When page is rendered, all the values from the requestBean are showed correctly, but all the anotherBean values show up empty. Even refreshing the page won't help.

If I trigger a button in page.xhtml to print out in the action method the values from anotherBean:

log.info("Another name: " + another.getName());

they print out fine.

I have in web.xml the saving method set for the server.

By the way, this is not the real naming convention I am using, but right now I'm in another computer without any IDEs nor JDK whatsoever, so I'm trying to replicate the code the best I can.

How can I show the correct values in page?


Solution

  • Try using,

    <h:outputText value="#{oneClass.another.name}" />
    <h:outputText value="#{oneClass.another.lastname}" />
    

    To view all the variables in sessionScope you can do a:

    <h:outputText value="#{sessionScope}" /> 
    

    This will confirm if "myOtherBean" is in session scope or not.