PrimeFaces dialog lazy loading (dynamic=“true”) does not work?

前端 未结 2 1632
离开以前
离开以前 2021-01-03 04:53

I have recently changed all my beans from RequestScoped to ViewScoped. Suddenly, the lazy loading of dialogs does not work. I am using PrimeF

2条回答
  •  遥遥无期
    2021-01-03 05:55

    have found some pretty easy workaround:

    Let's quote BalusC's answer on this other question: Skip executing when parent UI component is not rendered

    The runs as being a taghandler during the view build time, while the rendered attribute is evaluated during the view render time.

    Regarding his first proposal:

    1. Use a view build time tag like around the part.

    So first add some new method to your bean. (may even be useful in some application scoped bean for reuse)

    public boolean isAjaxRequest() {
        boolean val = FacesContext.getCurrentInstance().getPartialViewContext().isAjaxRequest();
        return val;
    }
    

    Then enclose your inside following :

     
        
            
        
    
    

    So at page load time, the request isn't ajax... and on other ajax requests on base page, the dialog won't be updated... But if you trigger your dialog

    
    

    and update it's content, it will finally be rendered!

    Please note following changes: The p:dialog id, p:commandButton update and p:commandButton oncomplete

提交回复
热议问题