H1大家!让JSF 2.0中的以下场景(Mojarra 2.2、Glassfish 4、Primefaces 4.0):
<!DOCTYPE html>
<html lang="fr"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Title</title>
</h:head>
<h:body onload="PF('dlg').show()">
<p:dialog widgetVar="dlg"
resizable="false" closable="false" >
<h:form id="form">
<h:outputLabel for="name" value="Name:" />
<p:inputText id="name" />
<p:commandButton id="submitButton" value="Submit" />
<p:commandButton id="cancelButton" value="Cancel"
onclick="alert('ok'); PF('dlg').hide();" />
</h:form>
</p:dialog>
</h:body>
</html>
问题是Primefaces对话框在隐藏后保持焦点:当取消对话框后按空格键或回车键时,您可以观察到警报"ok"将再次显示!
当试图使用:onclick="alert('ok'); PF('dlg').hide(); PF('dlg').blur()"
或onclick="alert('ok'); PF('dlg').hide(); PF('dlg').focusout()"
设置对话框的焦点时,由于对话框再次出现,似乎整个主体都被重新加载了。。。
我做错什么了吗?这是我的误解还是Primefaces中的错误?如有任何帮助,我们将不胜感激:)
它正在使用:
document.activeElement.blur()
而不是:
PF('dlg').blur()