如何在JSF 2.0中重定向 [英] How can I redirect in JSF 2.0

查看:133
本文介绍了如何在JSF 2.0中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从JSF页面中的链接重定向,该怎么做?

I want to redirect from a link in a JSF page, how can I do it?

在HTML中,我可以为此使用<a>标记.但是在JSF中,我使用<h:outputLink><h:commandLink>,因为它们可以有条件地呈现.我想将链接重定向到同一应用程序中的其他页面或外部URL.我如何用JSF做到这一点?如何在<h:commandLink>中使用action?

In HTML I can use <a> tag for this. But in JSF I use <h:outputLink> or <h:commandLink> as they can be conditionally rendered. I want redirect link to other page in same application or to an external URL. How can I do it with JSF? How can I use action in <h:commandLink> for this?

推荐答案

假定您要重定向到位于Web根文件夹中的some.xhtml:

Assuming that you'd like to redirect to some.xhtml which is placed in web root folder:

  1. 您可以继续使用纯HTML.

  1. You can just continue using plain HTML.

<a href="#{request.contextPath}/some.xhtml">go to some page</a>

对于条件渲染,只需将其包装在<ui:fragment> .

For conditional rendering, just wrap it in an <ui:fragment>.

或在隐式导航中使用<h:link>.

<h:link outcome="/some" value="go to some page" />

注意:无需添加上下文路径,也无需包含FacesServlet映射.

Note: no need to prepend context path nor to include FacesServlet mapping.

或将<h:commandLink>?faces-redirect=true一起使用.

<h:commandLink action="/some?faces-redirect=true" value="go to some page" />

注意:无需添加上下文路径,也无需包含FacesServlet映射.

Note: no need to prepend context path nor to include FacesServlet mapping.

或使用<h:outputLink>,但是您需要指定上下文路径.

Or use <h:outputLink>, but you need to specify context path.

<h:outputLink value="#{request.contextPath}/some.xhtml" value="go to some page" />


重定向到外部URL已在以下重复项中得到解答:重定向到外部URL在JSF中.

Redirecting to an external URL is already answered in this duplicate: Redirect to external URL in JSF.

  • How to navigate in JSF? How to make URL reflect current page (and not previous one)
  • When should I use h:outputLink instead of h:commandLink?
  • JSF implicit vs. explicit navigation

这篇关于如何在JSF 2.0中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆