【问题标题】:Adding omnifaces project gives incorrect url at redirect添加omnifaces项目会在重定向时提供不正确的url
【发布时间】:2014-01-30 12:11:07
【问题描述】:

在 jsf 项目中使用 omnifaces 1.6,在 glassfish 3.1.2 上使用 primefaces 3.5

FacesContext.getCurrentInstance().getExternalContext().redirect("localhost/my-project/views/index.jsf");  

使用此代码将重定向到带有 url localhost/my-project/的页面
这个问题是当添加omnifaces而没有omnifaces时,该功能可以正常工作,没有问题

【问题讨论】:

  • 这不是默认行为。您是否更改了 web.xmlfaces-config.xml 中的任何内容?也许与 FacesViews 相关?
  • 在我的 web.xml 中,我使用的是 auth-method FORM,当打开 index.jsf 时,会打开一个重定向到登录页面,并且在 index.jsf 页面的 preRenderView 处,我正在调用这行代码 @ 987654325@ 将我重定向到 localhost/my-project/ 而不是 index.jsf 在没有全方位的情况下重定向 url 是正确的
  • 具有 WAR 风格的 SSCCE 会有所帮助。正如 unwichtich 的回答所表明的那样,我至少可以说给定的重定向 URL 确实很奇怪。
  • 可能很奇怪,但是如果没有omniface jar文件重定向是正确的,而添加jar文件重定向会发生变化
  • 如前所述,我无法回答这个问题,除非我看到 SSCCE 具有 WAR 的味道。

标签: jsf primefaces glassfish omnifaces


【解决方案1】:

我不知道您期望什么,但是当您重定向到 localhost/my-project/ 时,重定向到 URL 为 localhost/my-project/ 的页面似乎是正确的行为。

也许你错过了端口(例如重定向到localhost:8080/my-project/),但通常它不是为了重定向到包含本地主机的URL,而是重定向到特定页面(例如重定向到index.jsfindex.xhtml)。你甚至不需要 webapp 上下文(即my-project),你可以像这样重定向到你的“主页”:

FacesContext.getCurrentInstance().getExternalContext().redirect("home.xhtml");

【讨论】:

    猜你喜欢
    • 2012-04-08
    • 2015-10-05
    • 1970-01-01
    • 2019-08-07
    • 2012-06-02
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多