最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if PrimeFaces widgetVar exists - Stack Overflow

programmeradmin4浏览0评论

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!

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!

Share Improve this question edited Jun 29, 2014 at 15:11 Hatem Alimam 10k4 gold badges46 silver badges58 bronze badges asked Jun 29, 2014 at 10:59 n00b programmern00b programmer 2,7017 gold badges41 silver badges57 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 24

You may use the following

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

评论列表(0)

  1. 暂无评论