升级到 JSF 2.2 后 faces-config 出现错误

问题描述 投票:0回答:2

将项目中的 JSF 实现从 Myfaces 1.1 升级到 MyFaces 2.2.12 后,我的 IDE (IntelliJ) 显示我的

navigation-rule
中所有
managed-bean
faces-config.xml
条目的错误。我已将该文件中的根元素从

更改为
<!DOCTYPE faces-config PUBLIC
        "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
        "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>

<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-rule>
    <navigation-case>
        <from-outcome>exampleOutcome</from-outcome>
        <to-view-id>/newpages/view1.jsp</to-view-id>
    </navigation-case>
</navigation-rule>

升级到 JSF 2.2 后,

navigation-case
元素被错误标记为红色下划线。当用鼠标悬停文本时,我收到错误消息:

Invalid content was found starting with element 'navigation-case'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":from-view-id}' is expected.

这是否意味着

from-view-id
已成为 JSF 2.2 的强制要求?

managed-bean
条目如

<managed-bean>
    <managed-bean-name>ExampleBean</managed-bean-name>
    <managed-bean-class>my.example.package.ExampleBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

产生类似的错误消息:

A field of identity constraint 'faces-config-managed-bean-name-uniqueness' matched element 'faces-config', but this element does not have a simple type.

我还没有发现任何关于升级到 JSF 2.2 时需要进行的结构性更改。 有趣的是,我在对 JSF 2.1 进行中间更改时没有收到此错误!

有人能指出我可能解决这个问题的方向吗?

jsf-2.2 myfaces faces-config
2个回答
0
投票

您必须在

<from-view-id></from-view-id>
之前插入一个空标签
<navigation-case>

示例:

<navigation-rule>
    <from-view-id></from-view-id>
    <navigation-case>
        <from-outcome>go_start</from-outcome>
        <to-view-id>/pages/start.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

-1
投票

试试这个:

<?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>
    <display-name>first_page.xhtml</display-name>
    <from-view-id>/first_page.xhtml</from-view-id>
    <navigation-case>
        <to-view-id>/second_page.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

© www.soinside.com 2019 - 2024. All rights reserved.