Search code examples
jsf-2primefacesblockui

Primefaces BlockUI blocks all with widgetvar


i want use Primefaces BlockUI's widgetvar (at the moment i use a modal dialog for it). The application should block only when i select something (a long method will call) and unblock after complete. But it blocks the full side on first side access. Make i something wrong?

When i block the table specific it works. (block="table") But i want block the whole page.

Use Primefaces 5.1 & Mojarra 2.2.8

Short example:

xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">

<h:head>
<title>test</title>
</h:head>

<h:body>
<h:form>

    <p:blockUI widgetVar="block" blocked="false"/>
    <p:dataTable id="table" value="#{myController.tableItems}" rowKey="#{data}"
        selection="#{myController.selectedItem}" selectionMode="Single"
        var="data">
        <p:ajax event="rowSelect" onstart="PF('block').show()"
            listener="#{myController.doSomething}"
            oncomplete="PF('block').hide()" />


        <p:column>#{data}</p:column>

    </p:dataTable>
</h:form>
</h:body>
</html>

Bean:

@ManagedBean
@ViewScoped
public final class MyController implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private List<String> tableItems;

private String selectedItem;

@PostConstruct
public void init() {
    tableItems = new ArrayList<String>();
    tableItems.add("test1");
    tableItems.add("test2");
}

public void doSomething(SelectEvent event){
    System.out.println("DO Something");
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
}

public String getSelectedItem() {
    return selectedItem;
}

public void setSelectedItem(String selectedItem) {
    this.selectedItem = selectedItem;
}

public List<String> getTableItems() {
    return tableItems;
}

public void setTableItems(List<String> tableItems) {
    this.tableItems = tableItems;
}
}

Solution

  • Add an id attribute the body and use that in the block= attribute on the blockui component