Binding a managed bean instance to composite component

前端 未结 1 2020
挽巷
挽巷 2020-12-04 00:15

I have a composite component (collapsiblePanel). The component uses the \"collapsible\" bean to provide the toggle function. When I use the same component multiple times on

1条回答
  •  星月不相逢
    2020-12-04 01:00

    You can use the componentType attribute of the to define a "backing component".

    E.g.

    
        ...
    
    
        ...
        
        ...
        
        ...
    
    

    with just a com.example.components.CollapsiblePanel

    @FacesComponent(value="collapsiblePanel") // To be specified in componentType attribute.
    public class CollapsiblePanel extends UINamingContainer { // Important! Must extend UINamingContainer.
    
        private boolean collapsed;
    
        public void toggle() {
            collapsed = !collapsed;
        }
    
        public boolean isCollapsed() {
            collapsed;
        }
    
    }
    

    However, when you want to have multiple of those components, then you should declare physically separate instances of them in the view. If this needs to happen dynamically, then you need to use to generate physically separate instances of them instead of with a single component. Otherwise you have to map all collapsed states by the client ID inside a Map. See for an example and more background information also Getting same instance of `componentType` in composite component on every use

    0 讨论(0)
提交回复
热议问题