How to address a component inside a looping naming container

前端 未结 3 1461
傲寒
傲寒 2020-12-20 01:54

I have the following structure (contents and attributes omitted):


    
        &l         


        
3条回答
  •  臣服心动
    2020-12-20 02:23

    As an update: In this particular case, using c:foreach was not an option, as both lists need to be dynamic (although this route saved me a lot of trouble in some other cases) Instead I added an attribute to the composite component to pass an optional "update scope" like so:

    
    

    By setting a default, I do not need to alter any uses of the components in a non-looping context. However, if I want to use it inside a ui:repeat I can pass an ID to the attribute that is wide enough to enclose the outer loop. Often, this would be an h:panelGroup id="wrapper" just around the ui:repeat.

    Obviously, this has quite some drawbacks: it updates all children of the loop, which could possibly result in a lot of unnecessary content being re-rendered. One nasty side-effect of this is that error messages and local values of these siblings are reset. In one of our pages it additionally causes all expanded panels to be reset into closed state.

    However, if these problems are of no importance (for example: my original example referred to a component that has no input fields or panels, but only feedback text and the action), the additional attribute can be a simple approach to work around the described issue.

提交回复
热议问题