How to use component binding in JSF right ? (request-scoped component in session scoped bean)

后端 未结 2 1445
天命终不由人
天命终不由人 2020-12-10 20:29

Mojara 2.1.21

I\'ve updated my question based on comments. I have two situation where a component is bound to server session bean. (Additional links with information

2条回答
  •  我在风中等你
    2020-12-10 20:36

    In JSF 2.x, unless you want to manipulate components programmatically (which is at its own also rather fishy), there is no sensible real world use case to bind components to a backing bean. For sure not if they are further not been used in the backing bean itself, or if it are solely their attributes which are been flattened out.


    As to the functional requirement of getting the current row of the data table, there are much better ways listed here, How can I pass selected row to commandLink inside dataTable?, for example if your environment supports EL 2.2:

    
        
            
    

    The two last requirements are totally unclear. At least, if you're doing something like:

    
    

    with in bean

    someComponent.setSomeAttribute(someAttribute);
    someComponent.setOtherAttribute(otherAttribute);
    

    then you should instead be doing

    
    

    Or, if you intend to be able to use the component somewhere else in the view like so

    
    ...
    
    

    and the instance is further nowhere been used in the bean, then just get rid of the unnecessary property altogether:

    
    ...
    
    

    If there is really, really no way for some unclear reason, then split all request scoped properties of the session scoped bean out into a separate request scoped bean which you in turn bind to form actions. The session scoped one can just be injected as a @ManagedProperty of the request scoped one.


    See also:

    • Binding attribute causes duplicate component ID found in the view
    • How does the 'binding' attribute work in JSF? When and how should it be used?

提交回复
热议问题