Validation 如何使用target=&x201C_空白”;仅在验证未失败时在新窗口中打开报告
我有一个报告需要在另一个选项卡中打开,但前提是验证没有失败。在我的例子中,验证失败,同一页在另一个选项卡中打开,出现验证错误。我不知道这是否是一个确定的答案,但您可以有两个答案:一个将触发服务器验证,另一个将在新页中调用报告。以下是开始代码:Validation 如何使用target=&x201C_空白”;仅在验证未失败时在新窗口中打开报告,validation,jsf,primefaces,report,new-window,Validation,Jsf,Primefaces,Report,New Window,我有一个报告需要在另一个选项卡中打开,但前提是验证没有失败。在我的例子中,验证失败,同一页在另一个选项卡中打开,出现验证错误。我不知道这是否是一个确定的答案,但您可以有两个答案:一个将触发服务器验证,另一个将在新页中调用报告。以下是开始代码: <h:form id="frmSomeReport"> <!-- your fields with validations and stuff --> <!-- the 1st commandLink tha
<h:form id="frmSomeReport">
<!-- your fields with validations and stuff -->
<!-- the 1st commandLink that will trigger the validations -->
<!-- use the oncomplete JS method to trigger the 2nd link click -->
<p:commandLink id="lnkShowReport" value="Show report"
oncomplete="if (args && !args.validationFailed) document.getElementById('frmSomeReport:lnkRealShowReport').click()" />
<!-- the 2nd commandLink that will trigger the report in new window -->
<!-- this commandLink is "non visible" for users -->
<h:commandLink id="lnkRealShowReport" style="display:none"
immediate="true" action="#{yourBean.yourAction}" target="_blank" />
</h:form>
<!-- a component to show the validation messages -->
<p:growl />
为了检查验证阶段是否包含任何错误,请检查Luiggi是否回答了POST问题。但是,如果报告可以通过GET请求获得,那么还有其他方法
oncomplete
中使用window.open()
<h:form>
...
<p:commandButton action="#{bean.submit}" update="@form"
oncomplete="if (args && !args.validationFailed) window.open('reportURL')" />
</h:form>
PrimeFaces\execute()
与window.open()一起使用
第一种方法要求在提交之前已经定义URL,后两种方法允许您使用动态URL,如so
window.open(“#{bean.reportURL}”)
什么验证?服务器端还是客户端?@Quentin OP指服务器端验证,是JSF生命周期的一部分。您是否使用其他框架,如RichFaces或PrimeFaces?im使用PrimeFaces;尝试了两种验证:服务器和客户端('required=true'),尝试了“form target=“\u blank with p:commandButton ajax=false”和“h:commandLink target=“\u blank””,我尝试了使用(!args.validationFailed)和bean中的一个变量(ajax=“{bean.variable}”)在p:commandButton中,但不起作用。您想在oncomplete
中检查args.validationFailed
。我开始学习JSF和PrimeFaces,想知道是否有一些示例可以使用此代码?因为我怀疑此示例是否适用于我的情况。我有一个表单,用户输入两个日期并将此表单提交给show记录以其他形式存在于数据表中。但需要验证。
<h:form>
...
<p:commandButton action="#{bean.submit}" update="@form" />
<h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">
window.open('reportURL');
</h:outputScript>
</h:form>
public void submit() {
// ...
PrimeFaces.current().executeScript("window.open('reportURL');");
}