Whats the correct way to create multiple instances of managed beans in JSF 2.0

后端 未结 3 2037
别跟我提以往
别跟我提以往 2020-12-18 03:20

If I want to create more than one instance of managed bean in JSF 2.0, under different names in the same scope, how should I proceed? Ideally, I want the equivilant to (for

3条回答
  •  借酒劲吻你
    2020-12-18 04:02

    In your case you should make use of the faces-config.xml. Implment your bean without the ManagedBean and RequestScope annotation. So your bean will not become a managed bean per default. You can than instance as much managedBeans as you need with different names, different scopes and at lease differnent properties. For example:

        
        MyManagedBean1
        org.MyManagedBean
        session
        
            value1
            int
            5
        
        
            value2
            int
            2
        
    
    
    
        MyManagedBean2
        org.MyManagedBean
        view
        
            value1
            int
            30
        
        
            value2
            java.lang.String
            project
        
    
    

    Don't think that descriptors are evil and annotations are the only way to implement your code.

提交回复
热议问题