別のタブで開く必要があるレポートがありますが、検証が失敗していない場合に限ります。私の場合、検証は失敗し、同じページが別のタブで開き、検証エラーが発生します。
5511 次
2 に答える
5
LuiggiはPOSTの問題に回答しました。ただし、レポートがGETリクエストで利用できる場合は、他の方法があります。
で使用
window.open()
しoncomplete
ます。<h:form> ... <p:commandButton action="#{bean.submit}" update="@form" oncomplete="if (args && !args.validationFailed) window.open('reportURL')" /> </h:form>
または、条件付きでをレンダリング
<h:outputScript>
しwindow.open()
ます。<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>
または、PrimeFaces
Primefaces#execute()
を。と一緒に使用しますwindow.open()
。public void submit() { // ... PrimeFaces.current().executeScript("window.open('reportURL');"); }
最初の方法では、送信する前にURLがすでに定義されている必要があります。後者の2つの方法では、このような動的URLを使用できますwindow.open('#{bean.reportURL}')
。
于 2013-01-29T14:43:52.143 に答える
1
これが決定的な答えかどうかはわかりませんが、2つ持つことができます。1つはサーバーの検証をトリガーし、もう1つは新しいページでレポートを呼び出します。開始コードは次のとおりです。
<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 />
検証フェーズにエラーが含まれているかどうかを確認するには、ajaxコマンドの実行中に検証エラー(required =“ true”)の兆候を見つける方法を確認します。
于 2013-01-29T13:56:08.180 に答える