【问题标题】:JSF navigation from action with param使用参数从动作中导航 JSF
【发布时间】:2015-04-20 15:28:21
【问题描述】:

我有以下导航规则:

<navigation-rule>
    <from-view-id>/pages/*</from-view-id>
    <navigation-case>
        <from-outcome>test</from-outcome>
        <to-view-id>/pages/test/edit.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

TestMB:

public String test() {
    return "test?id=1";
}

和 test.xhtml:

<h:commandLink action="#{testMB.test}">click</h:commandLink>

但如果return "test?id=1"; 则不起作用。我不想使用return "/pages/test/edit.xhtml?id=1";,我想使用抽象名称test

【问题讨论】:

标签: jsf jsf-2.2


【解决方案1】:

如果您要向 URL 添加 GET 参数,请注意不能使用 &lt;navigation-case&gt;(在您的示例中为 test)。唯一可行的方法是如果您有一个特定的 URL/页面,如下所示:

  public String test() {

      return "edit.xhtml?id=1&faces-redirect=true";
  }

重定向+参数机制仅适用于要定向到的明确页面/URL。它与 JSF 提供的 navigation-case 机制不兼容。


如果出于某种原因,您需要导航箱为导航模式,则需要在 faces-config 文件中定义导航参数:

    <to-view-id>/pages/test/edit.xhtml</to-view-id>
    <redirect>
        <view-param>
            <name>id</name>
            <value>1</value>
        </view-param>
    </redirect>

redirect 标记用于指定 faces-redirect 参数以及所需的 GET 参数 id


一种更好的形式是您无需对值进行硬编码,而是通过值绑定使其动态化:

   <redirect>
        <view-param>
            <name>id</name>
            <value>#{yourBean.redirectValue}</value>
        </view-param>
    </redirect>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2013-01-22
    • 2011-11-21
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    相关资源
    最近更新 更多