Julian Ray wrote:
[1] Do you mean instantiated or accessed? You can access a managed bean from
anyother managed bean using. If the bean is not already in scope it will be
instantiated

    protected Object getValue(String expr) {
        ValueBinding vb = getApplication().createValueBinding(expr);
        return (vb.getValue(getFacesContext()));
    }

We use a base class for session beans and provide quickaccess to named
beans.  This is very similar to how Sun's Creator 1 was organized.

[2] You might have more luck using a filter and/or listeners to handle
re-directs and session management. You should find some links on this in
this and other discussion boards.

-----Original Message-----
From: Ondrej Svetlik [mailto:[EMAIL PROTECTED] Sent: Friday, May 26, 2006 11:10 AM
To: MyFaces Discussion
Subject: Bean instantiation and dispatching

Hello all,

I have two problems:

1. I have several managed-beans and I access one of them (session
scoped) from the others. I need it to be instantiated on every page even
when it is not referenced there. Is there any possibility to do it?

2. Another request scoped bean is used to control access. It also access the
first bean to check whether the user is logged in and it should redirect to
login page in case the user is not logged in. I tried to use
ExternalContext.dispatch() but I got an exception saying that flush cannot
be called inside custom tags. Any ideas?

Thanks for any help, link or idea.

Best regards

Ondrej Svetlik

Hello,

Thanks for your answer.

I really mean instantiation. I'm accessing the bean through ExternalContext like this:

private synchronized void setSessionBean() {
        if (session == null) {
                FacesContext facesContext = getFacesContext();
                ExternalContext e = facesContext.getExternalContext();
                Map<String, Object> sessionBeans = e.getSessionMap();
                session = (MySession) sessionBeans.get("mySession");
        }
}

The problem is, that mySession is a session-scoped managed bean. It is instantiated at the time it is first referenced from the page, for example here:

<h:outputText value="#{mySession.user}" />

But there are pages with no such reference and still there are other beans that need the session bean have instantiated. I have no idea how the objects get instantiated in JSF, may be I should just create a new instance of MySession and add it to the sessionBeans map, but will it really register it to the session?

Ad 2. thanks, I'll just look around.

Best regards

Ondrej Svetlik

Reply via email to