Skip to content

Commit

Permalink
Added support for Faces 4 changed xmlns namespaces
Browse files Browse the repository at this point in the history
Since Jakarte EE Faces 4 the xmls namespaces were changed from `http://xmlns.jcp.org/jsf` to `jakarta.*`.
(see jakartaee/faces#1553)

This change adds new namespace support for:
* Generation of new JSF pages
* Tag suggestion in faces xhtml editor view
* Automatical addition of missing namespace decleration when new taglib is used

Reference: apache#6069
  • Loading branch information
asbachb committed Jun 18, 2023
1 parent 5af5f30 commit a4e8c7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ private static boolean isJSF30(WebModule wm) {
return classpath != null && classpath.findResource("jakarta/faces/flow/Flow.class") != null; //NOI18N
}

private static boolean isJSF40(WebModule wm) {
ClassPath classpath = ClassPath.getClassPath(wm.getDocumentBase(), ClassPath.COMPILE);
return classpath != null && classpath.findResource("jakarta/faces/lifecycle/ClientWindowScoped.class") != null; //NOI18N
}

public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
// Here is the default plain behavior. Simply takes the selected
// template (you need to have included the standard second panel
Expand Down Expand Up @@ -231,7 +236,9 @@ public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
template = templateParent.getFileObject("JSP", "xhtml"); //NOI18N
WebModule wm = WebModule.getWebModule(df.getPrimaryFile());
if (wm != null) {
if (isJSF30(wm)) {
if (isJSF40(wm)) {
wizardProps.put("isJSF40", Boolean.TRUE);
} else if (isJSF30(wm)) {
wizardProps.put("isJSF30", Boolean.TRUE);
} else if (isJSF22(wm)) {
wizardProps.put("isJSF22", Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?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">
<#if isJSF22?? || isJSF30??>
<html xmlns="http://www.w3.org/1999/xhtml"
<#if isJSF40??>
xmlns:h="jakarta.faces.html">
<#elseif isJSF22?? || isJSF30??>
xmlns:h="http://xmlns.jcp.org/jsf/html">
<#elseif isJSF20??>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<#else>
<html xmlns="http://www.w3.org/1999/xhtml">
</#if>
<#if isJSF20?? || isJSF22?? || isJSF30??>
<#if isJSF20?? || isJSF22?? || isJSF30 || isJSF40??>
<h:head>
<title>Facelet Title</title>
</h:head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class NamespaceUtils {
public static final String SUN_COM_LOCATION = "http://java.sun.com"; //NOI18N

/** Mapping of the new namespace to the legacy one. */
public static final Map<String, String> NS_MAPPING = new HashMap<String, String>(8);
public static final Map<String, String> NS_MAPPING = new HashMap<String, String>(16);

static {
NS_MAPPING.put("http://xmlns.jcp.org/jsf/html", "http://java.sun.com/jsf/html"); //NOI18N
Expand All @@ -50,6 +50,15 @@ public final class NamespaceUtils {
NS_MAPPING.put("http://xmlns.jcp.org/jsf/composite", "http://java.sun.com/jsf/composite"); //NOI18N
NS_MAPPING.put("http://xmlns.jcp.org/jsf", "http://java.sun.com/jsf"); //NOI18N
NS_MAPPING.put("http://xmlns.jcp.org/jsf/passthrough", "http://java.sun.com/jsf/passthrough"); //NOI18N

NS_MAPPING.put("jakarta.faces.html", "http://java.sun.com/jsf/html"); //NOI18N
NS_MAPPING.put("jakarta.faces.core", "http://java.sun.com/jsf/core"); //NOI18N
NS_MAPPING.put("jakarta.tags.core", "http://java.sun.com/jsp/jstl/core"); //NOI18N
NS_MAPPING.put("jakarta.tags.functions", "http://java.sun.com/jsp/jstl/functions"); //NOI18N
NS_MAPPING.put("jakarta.faces.facelets", "http://java.sun.com/jsf/facelets"); //NOI18N
NS_MAPPING.put("jakarta.faces.composite", "http://java.sun.com/jsf/composite"); //NOI18N
NS_MAPPING.put("jakarta.faces", "http://java.sun.com/jsf"); //NOI18N
NS_MAPPING.put("jakarta.faces.passthrough", "http://java.sun.com/jsf/passthrough"); //NOI18N
}

/**
Expand Down

0 comments on commit a4e8c7b

Please sign in to comment.