【发布时间】:2014-10-09 09:01:15
【问题描述】:
我有一个带有多个按钮的表单和一个显示“删除用户数据”的链接。单击链接后,会在执行任何操作之前显示确认弹出窗口。这是代码:
<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>
在表单中,我有很多字段,但是有问题的是文本字段,因为当用户在其中输入文本并按Enter键时,会立即调用方法deleteUserData(无需确认弹出)。下面是一个两个字段的代码,例如:
<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>
以上所有代码(2 个 div 和一个确认对话框)都在 <h:form> 内
所以,我不明白,为什么在 Enter 上执行命令按钮的动作监听器?
【问题讨论】:
标签: jsf input actionlistener enter commandbutton