问题描述:

I have the following declaration on my faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config version="2.1"

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xml="http://www.w3.org/XML/1998/namespace"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">

<name>Arial-Functions</name>

</faces-config>

I get the following Eclipse problem:

cvc-complex-type.2.2: Element 'name' must have no element [children],

and the value must be valid, line 6, XML Problem

Also:

cvc-pattern-valid: Value 'Arial-Functions' is not facet-valid with

respect to pattern '($||\p{L})(\p{L}|\p{Nd}||$)*' for type

'null',line 6, XML Problem

Line 6 of the XML is: <name>Arial-Functions</name>.

What am I doing wrong? PS: This deploys nicely on TomEE Plus and Wildfly 8.x

网友答案:

The definition the the name element in web-facesconfig_2_1.xsd:

<xsd:element name="name"
  type="javaee:java-identifierType"
  minOccurs="0"
  maxOccurs="1">

The definition of the java-identifierType in javaee_5.xsd:

<xsd:complexType name="java-identifierType">
  <xsd:annotation>
    <xsd:documentation>

The java-identifierType defines a Java identifier.
The users of this type should further verify that
the content does not contain Java reserved keywords.

    </xsd:documentation>
  </xsd:annotation>
  <xsd:simpleContent>
    <xsd:restriction base="javaee:string">
  <xsd:pattern value="($|_|\p{L})(\p{L}|\p{Nd}|_|$)*"/>
    </xsd:restriction>
  </xsd:simpleContent>
</xsd:complexType>

Arial-Functions is not a valid Java identifier.

You can test matches with:

boolean match = "Arial-Functions".matches("($|_|\\p{L})(\\p{L}|\\p{Nd}|_|$)*");
System.out.println(match);

I expect the JSF configuration parser is not validating the XML against the schema and ignores the name element in any case.

相关阅读:
Top