eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
371 stars 138 forks source link

Cannot invoke "com.sun.faces.config.manager.FacesSchema.loadSchema()" because "schemaId" is null|#] #24632

Closed hhallenyang closed 9 months ago

hhallenyang commented 9 months ago

Environment Details

Problem Description

I am migrating my project from Glassfish 4 to Glassfish 7. I got an exception when I run the project on Netbean 19 with Glassfish 7.0.9 server. I can run the same project on Netbeans 8.2 with Glassfish 4 successfully.

The problem is easily reproducible.

Stack traces or command outputs

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: com.sun.faces.config.ConfigurationException: Unable to parse document 'file:/C:/Users/allen/Documents/projects/emlucy/TagLib/TagLib/target/TagLib-1.0/WEB-INF/mytagLab.xml': Cannot invoke "com.sun.faces.config.manager.FacesSchema.loadSchema()" because "schemaId" is null|#]

Steps to reproduce

  1. Create a new Maven web application on Netbeans 19.
  2. Edit web.xml and pom.xml as shown below.
  3. Create /WEB-INF/mytagLab.xml and /tags/sample_tag.xhtml as shown below.

Sample code/application

Here is the content of the web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=https://jakarta.ee/xml/ns/jakartaee
   xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
   xsi:schemaLocation=[https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd](https://jakarta.ee/xml/ns/jakartaee%20https:/jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd)
   version="6.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>jakarta.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/mytagLab.xml</param-value>
    </context-param>
</web-app>

Here is the content of the pom.xml.

<project xmlns=http://maven.apache.org/POM/4.0.0 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
         xsi:schemaLocation=[http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd](http://maven.apache.org/POM/4.0.0%20http:/maven.apache.org/xsd/maven-4.0.0.xsd)>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.snfsoft</groupId>
    <artifactId>TagLib</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>TagLib-1.0</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jakartaee>10.0.0</jakartaee>
    </properties>

    <dependencies>
        <!--ok list start -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>10.0.0</version>
            <classifier>jakarta</classifier>
        </dependency>
        <!--ok list end -->
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>10.0.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
        </plugins>
    </build>
</project>

The content of 'mytagLab.xml'.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<facelet-taglib>
    <namespace>http://mycompany.com/tags</namespace>
    <tag>
        <tag-name>sample_tag</tag-name>
        <source>../tags/sample_tag.xhtml</source>
    </tag>
</facelet-taglib>

The content of /tags/sample_tag.xhtml'

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html     xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:ui="http://java.sun.com/jsf/facelets">

    <!--label_value-->
    <h:body>
        <ui:composition>
            <h:panelGroup rendered="#{not empty rendered ? rendered :  true}">
                <h:outputLabel value="#{label}:" title="#{title}" />
            </h:panelGroup>
            <h:outputText value="#{value}" />
        </ui:composition>
    </h:body>
</html>

Impact of Issue

I could not continue on migrating without fixing this problem.

Please choose one each Type, Component, and Priority label

Priority: high

arjantijms commented 9 months ago

The root tag of your taglib file (<facelet-taglib>) should have a schema. In your case it's completely empty.

For the current version in GlassFish 7 (Faces 4):

<facelet-taglib id="someId"
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facelettaglibrary_4_0.xsd"
    version="4.0"
>

See e.g. https://github.com/omnifaces/showcase/blob/master/src/main/webapp/WEB-INF/showcase.taglib.xml

hhallenyang commented 9 months ago

Thank you. The exception went away.

Here is the XHTML page I am referring the tag with 't'. However, the system can't find the namespace "http://mycompany.com/tags" when I try to call my tag "sample_tag" in my pages. What am I missing?

Here is my sample page.

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:t="http://mycompany.com/tags" >

<h:body>
    <ui:composition >
        <t:simple_tag label="My Label" value="My Value" />
    </ui:composition>
</h:body>

arjantijms commented 9 months ago

What am I missing?

These questions are best asked at https://stackoverflow.com ;)

hhallenyang commented 9 months ago

Thank you.