So I'm pretty new to jsf, I want a confirm dialog to be shown only if an attribute is set to true in my backing bean. I have something like this.
I have a data table which is multi selectable. When you select items in the table, an attribute get sets in the backing bean to hold those items.
Basically what the "showDeleteDialog()" method does, is check to see if any of those items in the list is selected, only then will it show the confirm dialog if the delete button is selected.
So what I want to happen is once a person has selected items from the data table, click the delete button. Have a confirm dialog come up and then delete the selected items. If the user has no items selected from the data table. I want the delete button to not show the confirm dialog.
<p:commandButton
styleClass="referralTaskDeleteBtn"
id="deleteButton"
value="#{loc['RegionAdmin.TaskType.DeleteButton']}"
icon="ui-icon-close"
update="deleteConfirmDialog,@this"
rendered="true"
action="#{referralTasksController.showDeleteDialog()}"
oncomplete="if (#{referralTasksController.displayDeleteDialog}) { PF('confirmDailogWidget').show(); }"
style="visibility: #{referralTasksController.toggleDeleteAndCompleteButtons()};"
disabled="#{not referralTasksController.enableEditButtons()}"
>
</p:commandButton>
and the backing bean method
public void showDeleteDialog(){
if (selectedReferralTasks.size()!=0)
this.displayDeleteDialog = true;
}
Anytime I click this, my dialog box only opens after the second click. Any ideas why? I'll include the dialog in case that is needed. Any help would be appreciate.
<p:outputPanel id="confirmationDailogOutputPanel">
<p:confirmDialog
id="deleteConfirmDialog"
header="Confirm Delete"
message="Are you sure you want to delete the selected Tasks"
showEffect="fade" hideEffect="fade"
widgetVar="confirmDailogWidget"
>
<p:commandButton value="#{loc['RegionAdmin.TaskType.DeleteButton']}" styleClass="confirmDialogDeleteButton" icon="ui-icon-check"
action="#{referralTasksController.deleteTasks()}"
oncomplete="PF('confirmDailogWidget').hide();"
update=":#{p:component('NoticePanel')},referralsTaskList,completeButton,deleteButton"
/>
<p:commandButton value="#{loc['RegionAdmin.TaskType.CancelButton']}"
styleClass="confirmDialogCancelButton"
icon="ui-icon-close"
oncomplete="PF('confirmDailogWidget').hide();"/>
</p:confirmDialog>
</p:outputPanel>