Shi*_*goy 2 navigation jsf new-window view-scope
我需要2.xhtml
在当前 JSF 页面(例如1.xhtml
)的新选项卡中打开一个新的JSF 页面(例如)。我应该使用哪个 JSF 组件?<h:commandLink>
或者<h:outputLink>
?
1.xhtml
单击链接以2.xhtml
在新选项卡中打开后,我不想失去当前页面的范围。
的豆1.xhtml
是@ViewScoped
。我应该把它改成@RequestScoped
吗?
在 HTML 中,通过 GET 请求在新窗口/选项卡中打开给定 URL 的链接将使用<a ... target="_blank">
.
在 JSF 中,您只需写下普通的 HTML:
<a href="#{request.contextPath}/2.xhtml" target="_blank">Open 2.xhtml in new window</a>
Run Code Online (Sandbox Code Playgroud)
您也可以使用<h:outputLink>
,这仅在您想使用其rendered
属性时才有用:
<h:outputLink value="#{request.contextPath}/2.xhtml" target="_blank">Open 2.xhtml in new window</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
您还可以使用<h:link>
which 可以获取导航结果而不是 URL,然后 JSF 将生成正确的 URL:
<h:link value="Open 2.xhtml in new window" outcome="2" target="_blank" />
Run Code Online (Sandbox Code Playgroud)
bean 作用域与这一切无关。只需为它保存的数据选择正确的一个。这<h:commandLink>
是不合适的,因为它触发 POST 请求而不是 GET 请求。
归档时间: |
|
查看次数: |
7195 次 |
最近记录: |