在jsf-2.2中的faces-config中传递重定向参数 [英] Passing redirect-param in faces-config in jsf-2.2

查看:75
本文介绍了在jsf-2.2中的faces-config中传递重定向参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧的jsf中,以下代码正常工作

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代码:

page1.xhtml code :

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

Java代码:

public class MyBean(){
   private double id;

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

在成功情况下,将打开page1.xhtml?id=0 page1,同时page1.xhtml?id=1使用参数id=1导航到page2.

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.

需要使用参数导航到page2.xhtml?id=1,因为在PostConstruct<f:viewAction>page2中已读取参数,并且需要根据此ID查找对象

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

在faces-config.xml文件中将jsf 2.2与mojarra javax.faces-2.2.8实现一起使用时,没有<view-param>,没有<redirect-param>对其进行更改,因此在没有id的情况下导航将无法导航到的成功方案page2.xhtml代替page2.xhtml?id=1

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

推荐答案

您可以使用旧方法.不要使用<redirect-param>,而要使用<view-param>. xsd( http://xmlns.jcp.org/xml/ns /javaee/web-facesconfig_2_2.xsd )会将其标记为false,但是mojarra javax.faces-2.2.8会以正确的方式静默使用它.

You can do it the old way. Instead of using <redirect-param> use <view-param>. The xsd (http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd) will mark it as false but mojarra javax.faces-2.2.8 will silently use it the right way you want it.

XSD将在Mojarra 2.3版本中修复,请参见其他答案"

The XSD will be fixed in the Mojarra 2.3 release, see the other 'answer'

示例:

<?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>

这篇关于在jsf-2.2中的faces-config中传递重定向参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆