非ajax请求的Primefaces就地问题 [英] Primefaces inplace issue with non-ajax request
问题描述
我正在使用primefaces就地编辑器. (已尝试使用素面3.2、3.3、3.4RC1和3.4快照)
I am using primefaces inplace editor. (tried primefaces 3.2, 3.3, 3.4RC1, and 3.4 snapshot)
通过非ajax请求提交表单时,如果表单中的其他必填字段未填写,则页面应重新加载并显示必填消息.但是实际发生的是:与页面重新加载和requiredMessage一起,已经显示了就地编辑器.如何解决这个问题?
When form is submitted through non-ajax request, and some other required field in the form was not filled, then the page should reload and show the required message. But what actually happens is: Along with page-reload and requiredMessage, the inplace editor is already being shown. How to solve this problem?
示例代码以重现问题
<h:form prependId="false">
<p:inplace editor="true" widgetVar="X">
<p:inputTextarea value="#{smsAlertBean.alertText}" />
</p:inplace>
</h:form>
<h:form prependId="false">
<p:selectOneMenu required="true" requiredMessage="Please select">
<!-- your values -->
</p:selectOneMenu>
<p:commandButton value="Submit" action="#{smsAlertBean.dummyAction}" ajax="false" />
</h:form>
推荐答案
我敢打赌这是<p:inplace>
中的错误.通过InplaceRenderer#encodeMarkup()
方法:
I'd bet that this is a bug in <p:inplace>
. From InplaceRenderer#encodeMarkup()
method:
boolean validationFailed = context.isValidationFailed();
String displayStyle = validationFailed ? "none" : "inline";
String contentStyle = validationFailed ? "inline" : "none";
它不检查验证失败是否涉及自己的"表单,因此将始终显示在验证失败上,而与提交的表单无关.除了编辑PrimeFaces源代码,创建自定义渲染器和/或发布错误报告外,您实际上无能为力.
It doesn't check if the validation failure concerns "own" form and would thus always display on a validation failure, regardless of the submitted form. There's not really much you can do against this other than editing the PrimeFaces source code, creatnig a custom renderer and/or posting a bug report.
您可以通过在widgetVar
上的JavaScript的帮助下手动关闭就地编辑器来解决此问题.它具有cancel()
函数,可关闭编辑器.
You could workaround this by manually closing the inplace editor with help of JavaScript on the widgetVar
. It has a cancel()
function which closes the editor.
<p:commandButton binding="#{foo}" value="Submit" action="#{smsAlertBean.dummyAction}" ajax="false" />
<h:outputScript rendered="#{param.containsKey(foo.clientId)}">X.cancel();</h:outputScript>
(因此,当实际按下命令按钮时将渲染此脚本)
但是,这只会对速度较慢的机器/浏览器产生难看的影响.就地编辑器闪烁.考虑将其报告为错误给PrimeFaces家伙,InplaceRenderer
应该首先检查验证失败是否涉及自己的表单.
This has however only an ugly effect on slow machines/browsers. The inplace editor flashes. Consider reporting it as a bug to the PrimeFaces guys, that the InplaceRenderer
should first check if the validation failure concerns own form or not.
这篇关于非ajax请求的Primefaces就地问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!