Primefaces 3.5.14,Omnifaces 1.6
JSF/Prime 中是否有一个组件看起来像一个按钮,但允许打开一个带有外部链接的新空白页面?因此,与普通链接不同,点击新页面 URL 必须最初从服务器保留,然后必须打开新页面。就像带有 action 属性的 commanButton,其中 action 方法的字符串结果确定新的 url。
当然我可以像Styling one JSF external link to make it look like a button那样使用p:button
但在这种情况下,我必须更新由 p:button
生成的链接,具体取决于每次在页面上执行的操作。这并不总是可取的。
最佳答案
你需要target="_blank"
在父表单上以提交到新窗口,您需要调用 ExternalContext#redirect()
(或 OmniFaces 的 Faces#redirect()
)在操作方法中,以便让目标窗口在给定的 URL 上发送新的 GET 请求。重要的是,当您使用 <p:commandButton>
而不是 <h:commandButton>
, 你还需要设置 ajax="false"
因为它不尊重 target="_blank"
.
因此,所以:
<h:form target="_blank">
<p:commandButton value="Submit" action="#{bean.submit}" ajax="false" />
</h:form>
与
public void submit() throws IOException {
String redirectURL = determineItSomehow();
Faces.redirect(redirectURL);
}
关于jsf - 如果目标 url 必须最初从服务器获取,如何使用 JSF 打开外部 url 的空白页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18919462/