How to address a component inside a looping naming container

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

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


    
        &l         


        
3条回答
  •  情书的邮戳
    2020-12-20 02:38

    The client ID as specified in must be available in both the server side by JSF's

    facesContext.getViewRoot().findComponent(clientId);
    

    (so that it could be found in order to render its new HTML representation for the ajax response)

    and in the client side by JavaScript's

    document.getElementById(clientId);
    

    (so that it could be updated/replaced by JS once the ajax response with new HTML content has arrived)

    As the runs during view render time only, the client ID with the row index does not represent a valid component in server side ("Cannot find component..." error from findComponent()), but it does represent a valid HTML element in the client side. Basically, you'd need the client ID without the row index for the server side and the one with the row index for the client side. But that just won't work for as it's (unfortunately) not possible to select the component tree state of a specific iteration round by alone findComponent().

    It should work fine when using JSTL and dynamically assigning component ID as it runs during view build time and also actually generates multiple fullworthy JSF components in the view tree instead of only one which is re-used multiple times during render.

    
        
            
                Some content here (outputText, etc.)
                
                   
                       
    

    This has however its own implications, certainly when used with composite components and also when used in nested loops. Your code is not complete enough to give insight and advice about that. It would for example break when this piece of code is placed in a composite component which is by itself also reused multiple times in a render time loop.

    See also:

    • JSTL in JSF2 Facelets... makes sense?
    • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"

提交回复
热议问题