Reputation: 3699
I have a lot of .xhtml views. Many of them have blockui elements, for example:
<p:blockUI block="tab" widgetVar="subscriberSelectBlocker">
</p:blockUI>
Sometimes there are more then 1 of them per view. To hide the blockUI above I have a method in the according bean SubscriberFilterBean.java:
public void hideSubscriberSelectBlockUi() {
RequestContext.getCurrentInstance().execute("subscriberSelectBlocker.hide()");
}
Now the problem is that I need to hide all existing blockuis at once. I could hide them individually like above, but that would mean that I would basically have the same code repeated over 15 times and the method to execute all these methods would be huge.
Is there a way to hide all elements of tag? Something like
public void hideSubscriberSelectBlockUi() {
RequestContext.getCurrentInstance().execute("p:blockui.hide()");
}
Upvotes: 0
Views: 871
Reputation: 1982
When you are specifying widgetVar in a PrimeFaces element, JavaScript widget object is instantiated and assigned to a global variable with the specified name in the window scope. This means that this objects could be found and manipulated.
I suggest finding them by blockui ids. Widget object contains it's id, so after obtaining all the global objects and all the blockui ids from page, we can determine which of the global objects are blockui widgets. Blockui ids from page could be obtained using jQuery class selector, as they all have common css style: .ui-blockui
.
Here is JavaScript example code that shows all blockui components on the page:
var keys = Object.getOwnPropertyNames( window );
var blocks = $('.ui-blockui');
var blockIds = [];
blocks.each (function (index,value) {
blockIds[index] = value.id;
});
$.each(keys, function (index, value) {
var obj = window[ value ];
if (obj != null) {
gObj = window[ value ];
if(gObj.blocker != undefined) {
if ($.inArray(gObj.blocker.attr('id'), blockIds) != -1) {
gObj.show();
}
}
}
});
Upvotes: 1