问题
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:
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.
来源:https://stackoverflow.com/questions/25780435/primefaces-close-dialog-on-init-dont-work