1

I have the following navigation-rule:

<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";
}

and test.xhtml:

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

But it is not working if return "test?id=1";. I do not want to use return "/pages/test/edit.xhtml?id=1";, I want to use the abstract name test.

Tiny
  • 27,221
  • 105
  • 339
  • 599
zerg
  • 255
  • 1
  • 3
  • 17

1 Answers1

5

If you're looking to add a GET parameter to the URL, know that you can't use the <navigation-case> (that is test in your example). The only way that'll work is if you had a specific URL/page as in:

  public String test() {

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

The redirection+parameter mechanism works only with a definite page/URL to direct to. It's not compatible with the JSF-provided navigation-case mechanism.


If for some reason, you require that the navigation case be the mode of navigation, you need to define the navigation parameter in your faces-config file:

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

The redirect tag is what specifies the faces-redirect parameter, along with your desired GET parameter id .


An even better form is where you're not hard-coding the value, rather making it dynamic via a value-binding:

   <redirect>
        <view-param>
            <name>id</name>
            <value>#{yourBean.redirectValue}</value>
        </view-param>
    </redirect>
kolossus
  • 20,559
  • 3
  • 52
  • 104