How to create a modular JSF 3.0 application?

204 views Asked by At

This is the jakarta 9 and jsf 3 version of this classic topic from several years ago: How to create a modular JSF 2.0 application?

The context is that I'm migrating a web app to tomcat 10.0.x, jakarta 9, jsf3, spring 6, etc as already detailed here:

Error creating bean with name 'entityManagerFactory' Factory method 'entityManagerFactory' threw exception with message

The porting (apart from some small malfunctions) seems almost ok, however there still seems to be a big problem: xhtml pages from external jars are no longer loaded.

These jars have this structure:

META-INF\resources\-here xhtml pages-
META-INF\faces-config.xml
META-INF\MANIFEST.MF
META-INF\web-fragment.xml

In the old working javax web app these file look like this:

faces-config.xml:

<?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">
</faces-config>

web-fragment.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 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-fragment_3_0.xsd">
 <name>name_of_the_resources_set</name> 
 </web-fragment>

In the new non-working jakarta 9 version they look like this:

faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
 <faces-config
    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-facesconfig_3_0.xsd"
    version="3.0">
</faces-config>

web-fragment.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<web-fragment 
id="WebFragment_ID" 
version="5.0" 
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-fragment_5_0.xsd">
 <name>name_of_the_resources_set</name> 
 </web-fragment>

(Notice that I hadn't defined any resource resolvers like in this BalusC suggestion: Note: since Servlet 3.0 and newer JBoss/JSF 2.0 versions, the whole ResourceResolver approach is not necessary if you keep the files in /META-INF/resources folder. The above ResourceResolver is only mandatory in Servlet 2.5 or older JBoss/JSF versions because they've bugs in META-INF resource resolving.)

I have an annotaged @EnableWebMvc config class which extends org.springframework.web.servlet.config.annotation.WebMvcConfigurer, in the method:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

I also try to change the pattern in:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/*/*").addResourceLocations("/resources/");
}

because I notice it seems that in spring 6 the ant matcher has changed, but nothing changed in the loadind of xhtml pages from jars and I'm not sure if this setting is involved.

For inclusions in this mode:

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pa="http://primefaces.org/verona" 
    xmlns:baseUtil="http://java.sun.com/jsf/composite/common/base/util">
    ...
    <baseUtil:outputTextTruncate msgToTruncate="#{myBean.myValue}" maxLength="12"/>

I get an error like this:

 jakarta.servlet.ServletException: <baseUtil:outputTextTruncate> Tag Library supports namespace: http://java.sun.com/jsf/composite/common/base/util, but no tag was defined for name: outputTextTruncate

And for inclusions like this:

<ui:include src="/common/base/pages/prospetto.xhtml" />

the error is this:

jakarta.servlet.ServletException: <ui:include src="/common/base/pages/prospetto.xhtml"> Invalid path : /common/base/pages/prospetto.xhtml

If, for test, I try to render a jsf page removing the inclusions of xhtml parts from jars the page is render.

In the old versions pre jakarta of the webapp all works fine (tomcat8-jdk8,spring 5 / tomcat 9 jdk17 spring 5.)

Any suggestions and ideas are welcome, thank you!

0

There are 0 answers