【问题标题】:CommandLink action redirect to external url not workingCommandLink 操作重定向到外部 url 不起作用
【发布时间】:2012-09-11 20:19:48
【问题描述】:

我正在使用 jsf 2。我在 facelet 文件中有一个指向外部 url 的链接。我当前的视图是 /app1/home.xhtml 和一个 h:commandLink 有这样的动作

<h:commandLink value="#{link}" action="#{action.redirect}" target="_blank"/>

action.redirect 重定向到的 url 是 /app2/info.do。然而,JSF 似乎试图将 url 的扩展名更改为 .xhtml。然后失败并显示错误消息。

com.sun.faces.context.FacesFileNotFoundException: /app2/info.xhtml 在 ExternalContext 中找不到作为资源

如何让它正确重定向?

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    不要在这里使用&lt;h:commandLink&gt;,这是错误的标签。它旨在提交 JSF POST 表单并导航到 JSF 视图,您显然不希望在此特定用例中发生这两种情况。

    只需使用&lt;h:outputLink&gt; 甚至纯HTML &lt;a&gt;。所以,

    <h:outputLink value="#{action.redirect}" target="_blank">#{link}</h:outputLink>
    

    <a href="#{action.redirect}" target="_blank">#{link}</a>
    

    请注意,这两种方法都不需要&lt;h:form&gt;

    【讨论】:

    • 也许我没有正确解释这一点。 action.redirect() 方法实际上是通过调用 FacesContext.getCurrentInstance().getExternalContext().redirect(redirectURL); redirectURL 需要按程序计算。因此 h:outputLink 将不起作用。
    • 这应该只是工作并且不会导致所描述的问题症状。您的具体问题可能是由其他地方引起的,或者您误解了具体问题。
    • 嗯,我不知道。我注意到 if 无论出于何种原因与 a:commandLink 一起使用。但不确定如何在新窗口中打开 a:commandLink
    • 我忘了提到的是我使用了weld,而且我知道weld 有类似的记录问题-community.jboss.org/message/759314#759314。因此,在这种情况下,焊接可能是导致扩展名从 .do 更改为 .xhmtl 的原因
    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 2016-05-05
    • 2012-10-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2014-08-30
    相关资源
    最近更新 更多