Passing redirect-param to faces-config in jsf-2.2

In old jsf the following code worked

<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=0page1 will be open, while page1.xhtml?id=1navigation to page2with the parameter id=1.

navigation in page2.xhtml?id=1with the parameter is necessary, because in the page2on parameter it is PostConstructeither <f:viewAction>read and it is required to find the object in accordance with this id

Using jsf 2.2 with implementation mojarra javax.faces-2.2.8 in the faces-config.xml file is not <view-param>there <redirect-param>, the change should not result in a successful scenario, when navigation without id, where it will be moved page2.xhtmlinsteadpage2.xhtml?id=1

+4
3

-. <redirect-param> <view-param>. Xsd (http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd) false, mojarra javax.faces-2.2.8 , .

: XSD Mojarra 2.3, .

:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2">
    <navigation-rule>
        <navigation-case>
            ...
            <redirect>
                <view-param>
                    <name>foo</name>
                    <value>bar</value>
                </view-param>
            </redirect>
        </navigation-case>
    </navigation-rule>
</faces-config>
+3

include-view-params="true" <redirect> faces-config.xml <view-param>.
<f:viewParam> (page2.xhtml).
, , :

faces-config.xml:

<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 include-view-params="true" />
    </navigation-case>
</navigation-rule>

page1.xhtml ( ):

<f:metadata>
    <f:viewParam id="id" name="id" value="#{myBean.id}" />
    <f:viewAction action="#{myBean.init()}"/>
</f:metadata>

page2.xhtml :

<f:metadata>
    <f:viewParam id="id" name="id"/>
</f:metadata>

ManagedBean ( ):

public class MyBean {
    private double id;

    public boolean init(){
        if(id > 0)
            return true;
        else
            return false;
    }

    // getter & setter for id
}
0

Use the old tag <view-param>when setting up, as Jaxt0r is mentioned in fooobar.com/questions/1565284 / ...

This is a JSF bug that has been fixed for 2.3. See https://java.net/jira/browse/JAVASERVERFACES-3399

0
source

All Articles