I have a form with several buttons and a link that says "Delete user data". Upon click on the link, a confirmation popup shows before any action takes place. Here is the code for this:
<p:confirmDialog closable="false"
header="#{bundle['remove.user.data']}"
message="#{bundle['remove.user.data.text']}"
severity="alert" widgetVar="deleteUserPopup">
<h:commandButton
actionListener="#{userBean.deleteUserData}"
value="#{bundle['yes']}" immediate="true"
onclick="deleteUserPopup.hide()">
<f:attribute name="userId"
value="#{userBean.user.id}" />
<f:ajax execute="@this" render="@all" />
</h:commandButton>
<h:commandButton value="#{bundle['no']}"
onclick="deleteUserPopup.hide()" type="button" />
</p:confirmDialog>
<div>
<h:commandLink>
<h:outputText value="#{bundle['remove.user']}" />
<h:graphicImage name="remove.png" library="img"
title="#{bundle['remove.user']}" />
<f:ajax event="click"
onevent="deleteUserPopup.show()" />
</h:commandLink>
</div>
In the form, I have a lot of fields, but it's the text fields that are problematic, because when a user enters text in it and hits on Enter, the method deleteUserData
is called immediately (without confirmation popup). Here is the code of one two fields for example:
<div>
<h:panelGrid columns="2">
<h:column>
<h:inputText
value="#{userBean.user.lastName}" id="userLastName" />
<h:message for="userLastName" styleClass="warning" />
</h:column>
<h:column>
<h:inputText
value="#{userBean.user.firstName}" id="userFirstName" />
<h:message for="userFirstName" styleClass="warning" />
</h:column>
</h:panelGrid>
</div>
All of the above code (2 divs and a confirm dialog) comes inside of a <h:form>
So, I don't get it, why on Enter the action listener of the command button is executed?