In old jsf the following code was working
<navigation-rule>
<from-view-id>/page1.xhtml</from-view-id>
<navigation-case>
<from-outcome>true</from-outcome>
<to-view-id>/page2.xhtml</to-view-id>
<redirect>
<view-param>
<name>id</name>
<value>#{myBean.id}</value>
</view-param>
</redirect>
</navigation-case>
</navigation-rule>
page1.xhtml code :
<f:metadata>
<f:viewParam id="id" name="id" value="#{myBean.id}" />
<f:viewAction action="#{myBean.init()}"/>
</f:metadata>
Java code :
public class MyBean(){
private double id;
public boolean init(){
if(id > 0)
return true;
else
return false;
}
}
In the success scenario when page1.xhtml?id=0
page1 will be opened while page1.xhtml?id=1
navigation to page2
with parameter id=1
.
navigation to page2.xhtml?id=1
with parameter is needed since in page2
on PostConstruct
or <f:viewAction>
parameter is read and needed to find object according to this id
Using jsf 2.2 with mojarra javax.faces-2.2.8 implementation in faces-config.xml file there is no <view-param>
there is <redirect-param>
changing them gives no success scenario where navigation is without id where it will navigate to page2.xhtml
instead of page2.xhtml?id=1
Try using
include-view-params="true"
attribute in<redirect>
element offaces-config.xml
instead of declaring parameters using<view-param>
tag.Also be sure to declare
<f:viewParam>
in the target page (page2.xhtml
).I believe I made your example work as you expected like this:
Navigation rule in faces-config.xml:
page1.xhtml code (unchanged):
page2.xhtml code:
ManagedBean (unchanged):