primefaces close dialog on init don't work

2019-09-21 03:16发布

Im'using Primefaces 5.0 and I tried to use PF Dialog Framework features, but with some problems. I open a dialog using openDialog() method. In the dialog bean I managed an init() method annotated with @PostConstruct. In that method I read parameters and load a list of records (to bind with a dataTable). All seems work fine... dialog opens, I choose a record , close with closeReturn and so on.

But I want that in init(), if a single record was found, I could close immediately the dialog. So I call closeDialog(), passing my bean... but nothing happens... the dialog opens and I have to close it manually. And this is frustrating...

Could anyone help me?

Thanks

1条回答
ゆ 、 Hurt°
2楼-- · 2019-09-21 03:35

You can use primefaces requestContext to close the dialog from your bean.

@PostConstruct
public void init() {
    recordList = loadListOfRecords();
    if ( recordList.size() == 1 ) {
        RequestContext.getCurrentInstance().execute('yourDialogWidgeVar.close()');
    }
}

This is just a possibility to close a dialog from Bean. I don't know if it fits to your demands. Please post your code next time. It is hard to figure out your problem without it.

查看更多
登录 后发表回答