Peter, I've just tried with a simple application to reproduce your
problem and it works ok to me, so there must be something wrong
there... this is my code:

[APP_BEAN]

public class AppBacking
{

    private String time;

    public AppBacking() {
        System.out.println("APP backing initializing");
        time = new Date().toString();
    }

    public String getTime()
    {
        return time;
    }

    public void setTime(String time)
    {
        this.time = time;
    }
}

[REQUEST_BEAN]

public class ReqBacking
{

    private AppBacking appBacking;

    public ReqBacking() {
        System.out.println("REQUEST initializing");
    }

    public AppBacking getAppBacking()
    {
        return appBacking;
    }

    public void setAppBacking(AppBacking appBacking)
    {
        this.appBacking = appBacking;
    }

}

[/REQ_BEAN]

[JSP]

<h:form id="form">
  <h:panelGrid id="grid" columns="2">
    <h:outputText value="#{reqBack.appBacking.time}"/>
    <h:commandButton value="test" action="none"/>
  </h:panelGrid>
</h:form>

[/JSP]

[CONFIG]

<managed-bean>
        <managed-bean-name>appBack</managed-bean-name>
        <managed-bean-class>
            org.apache.myfaces.blank.AppBacking
        </managed-bean-class>
        <managed-bean-scope>application</managed-bean-scope>
    </managed-bean>

    <managed-bean>
        <managed-bean-name>reqBack</managed-bean-name>
        <managed-bean-class>
org.apache.myfaces.blank.ReqBacking</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>appBacking</property-name>
            <value>#{appBack}</value>
        </managed-property>
    </managed-bean>

[/CONFIG]

And the output I am getting, while clicking the button:

REQUEST initializing
APP backing initializing
REQUEST initializing
REQUEST initializing
REQUEST initializing
...

So you can see that everything is working as expected. It is not the
case, but if you were setting a bean with shorter lifespan to another
bean (a request managed bean into an application managed bean, for
instance) an exception would be thrown.

Hope that helps,

Bruno

2005/11/21, Peter Maas <[EMAIL PROTECTED]>:
> The bean should acts as a central service locator for my jsf beans, and
> apart from the per request initializations is works as a shine.
>  Logging info written in the beans' constructor shows that the bean is
> instantiated every time over. The constructors are public, so the bean is
> not a singleton; should it be?
>
>  the bean is injected into other managed beans like this:
>
>      <managed-bean>
>          <description>
>              Service locator of the business services
>          </description>
>
> <managed-bean-name>serviceLocatorBean</managed-bean-name>
>          <managed-bean-class>
>              com.dp.jsf.ServiceLocatorBean
>          </managed-bean-class>
>
> <managed-bean-scope>application</managed-bean-scope>
>      </managed-bean>
>
>      <managed-bean>
>
> <managed-bean-name>CardsListBean</managed-bean-name>
>          <managed-bean-class>com.dp.jsf.CardListBean</managed-bean-class>
>          <managed-bean-scope>request</managed-bean-scope>
>          <managed-property>
>              <property-name>serviceLocator</property-name>
>              <value>#{serviceLocatorBean}</value>
>          </managed-property>
>      </managed-bean>
>
>
>  Every time the CardsListBean is accessed, I see logging info from the
> service locator constructor. Is the way I inject the locator into the target
> bean correct or is this what causes the strange behaviour?
>
>  kind regards,
>
>  Peter
>
>
>
> On 11/21/05, Bruno Aranda <[EMAIL PROTECTED]> wrote:
> > Something wrong may be happening. A bean in application scope should
> > only initialize one time and you can use it as long as your
> > application is alive without being initialized again... How are you
> > checking the initialization of that bean?
> >
> > Bruno
> >
> > 2005/11/21, Peter Maas <[EMAIL PROTECTED]>:
> > > Hi all,
> > >
> > >  I tried to figure out if it is possible to share bean instances between
> > > different request. Currently the beans I have configured to be in
> > > application scope are instantiated for each request... is this the way
> it
> > > should work or am I doing something wrong?
> > >
> > >  regards,
> > >
> > >  Peter
> > >
> >
>
>

Reply via email to