0

I have read that JSF managed beans are Singleton in nature by default. I have a doubt regarding this. If I have two Java class A and B like this:

class A {

    private B b1;

    private B b2;

    private B b3;

    here getters ans setters 
}

class B {

    String a;

    getters and setters

}

And My JSF faces-config.xml:

    <managed-bean>
                <managed-bean-name>bean_A</managed-bean-name>
                <managed-bean-class>...</managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope> 
            <managed-property>
                <property-name>b1</property-name>
                <value>#{bean_B}</value>
            </managed-property>
            <managed-property>
                <property-name>b2</property-name>
                <value>#{bean_B}</value>
            </managed-property>
            <managed-property>
                <property-name>b3</property-name>
                <value>#{bean_B}</value>
            </managed-property>
    </managed-bean>

    <managed-bean>
                <managed-bean-name>bean_B</managed-bean-name>
                <managed-bean-class>...</managed-bean-class>
                <managed-bean-scope>none</managed-bean-scope> 
    </managed-bean>

So In above scenario b1, b2 and b3 in class A, would refer to same object or container will manage to assign them three different objects?

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
  • By the way, you made a typo on your profile summary, you typed *"Woking with Java."* instead of *"Working..."*. – Jean-François Savard Sep 30 '15 at 16:55
  • No managed bean is a singleton bean. Where did you read it? – Tiny Sep 30 '15 at 18:21
  • @Tiny:I have read it on internet blogs. If not so then you mean to say that these three will point to different objects? – Gaurav Jeswani Sep 30 '15 at 20:00
  • @Jean : Thanks a lot for letting me know. I will correct it. :) – Gaurav Jeswani Sep 30 '15 at 20:01
  • The behavior of `none` scoped bean is explained in the dupe. As to the assumption that beans are singletons, this is nonsense. You must have misunderstood the article, or the article is of bad quality. Without a link to that article, we can't help you further (my initial guess would be that the article is actually talking about Spring managed beans, which are indeed by default singletons). As to choosing the right bean scope, head to http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope – BalusC Sep 30 '15 at 20:34

0 Answers0