简体   繁体   中英

Check if PrimeFaces widgetVar exists

I have a Primefaces commandButton, that calls a datatable filter in its onComplete. The datatable is referenced by a widgetVar:

<p:commandButton id="addFishBtn" 
                    title="Add Fish"
                    update="fishForm:FishTbl"
                    action="#{backingBean.addFish()}" 
                    oncomplete="fishTable.filter()"/>

The problem is, that fishTable doesn't always exist when this button is pressed. It it doesn't exist, the app just gets stuck. I tryed something like this from other SO questions:

oncomplete="if(typeof(fishTable) != 'undefined') {fishTable.filter()}"

But it doesn't seem to be doing anything. Is there any proper way to check if a widgetVar currently has any value?
Thanks!

You may use the following

if(PrimeFaces.widgets['fishTable']) {
   //widgetVar does exist
   PF('fishTable').filter();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM