Which XML namespace to use with JSF 2.2 and up
Asked Answered
R

3

15

I have migrated my application from JSF 1.2 to 2.2.

It used XML namespaces on java.sun.com domain like xmlns:f="http://java.sun.com/jsf/core". However, Oracle's Java EE 7 tutorial is using XML namespaces on xmlns.jcp.org domain like xmlns:f="http://xmlns.jcp.org/jsf/core".

Which one is recommended and why was this changed?

Remotion answered 26/6, 2015 at 8:41 Comment(3)
Go with http://xmlns.jcp.org/..., if you are using JSF 2.2.x. It is a new JSF 2.2 thing (JSF 2.4 does not exist, by the way which you should have mistakenly typed in. It should be JSF 2.2.4 instead).Convolute
Jsf 2.4? Latest stable is 2.2 and 2.3 is in development. I think you are mixing things up. 2.2 already has the jcp namespaceAlliterative
Yes it's 2.2.4. It's a mistake when I typed.Remotion
M
22

Which one is recommended?

For Java EE 7 and 8, go ahead with XML namespaces on xmlns.jcp.org domain. This was newly introduced since Java EE 7 in 2013 (which covers a.o. JSF 2.2, Servlet 3.1, CDI 1.1, etc). Do note that this not only affects Facelets files, but also XML configuration files such as faces-config.xml, web.xml, beans.xml, etc.

The old XML namespaces on java.sun.com are still there for backwards compatibility, but the support will eventually disappear in a future Java EE version. You should migrate your code base as soon as you can. It should be a trivial task using "find and replace in all files" facility offered by the average IDE.

Only older Mojarra 2.2.0 / 2.2.1 versions have had bugs related to the XML namespace changes, but those should not manifest in newer versions. See also a.o.


and why was this changed?

Because Java is not from Sun anymore since 2010. Note that they were smart to not make it java.oracle.com or something tight coupled to the currently owning company. It's now nicely and independently tied to the JCP (Java Community Process), the one really responsible for managing the Java (EE) specifications.


And then a few years later ...

Since Java EE was taken over by Eclipse and rebranded to Jakarta EE, the XML namespace domain is changed from xmlns.jcp.org to jakarta.ee to make it further independent. Moreover, the specification process is also not anymore owned by JCP.

Faces 4 in Jakarta EE 10 has as per spec issue 1553 also taken a step further to not anymore use a URL as XML namespace URI, but a URN instead: xmlns:f="jakarta.faces.core". The reason for using a URN instead of URL is because those taglib URIs are in first place not available as physical web resources returning some sort of XSD file and therefore only caused confusion among starters.

See also:

Mighty answered 26/6, 2015 at 13:38 Comment(1)
What changes needed in faces-config.xml, web.xml, beans.xml, etc? I did quick check and it seems to be working by just changing namespace. It would be helpful if you can share any suitable link.Remotion
J
13

I made a brief summary of all the new official oracle namespaces:

<!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://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
    xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
    xmlns:cc="http://xmlns.jcp.org/jsf/composite"
    xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"      
    xmlns:jsf="http://xmlns.jcp.org/jsf">

    <!-- Content here -->
</html>

I use this as template for all of my .xhtml files. Details can be found in the official facelet tag library: JavaServer Faces 2.2 Facelets Tag Library Documentation

Hope this helps :)

Jacket answered 27/5, 2018 at 18:56 Comment(0)
P
1

For future visitors having namespace confusion/issue:

I would like to highlight the general way to find out which namespace to use:

  • If you want to use tags from JSF HTML tag library or JSF core tag library then open the JSF implementation JAR (like Oracle Mojarra, Apache MyFaces- myfaces-impl-2.3.1.jar) and find the tag library's .tld or .xml file (you can find it under META-INF directory) and use the namespace mentioned over there.
  • If you want to use the RichFaces or PrimeFaces then open their implementation JAR (like richfaces-components-ui-4.0.0.Final.jar, or primefaces-6.2.jar) and do same thing as above.

If implementation has .tld (like rich.tld) then you can use the value of <uri> element for example <uri>http://richfaces.org/rich</uri>. And if implementation has .xml (like rich.taglib.xml) then you can use the value of <namespace> element for example <namespace>http://richfaces.org/rich</namespace>

What I have mentioned above is strictly related to JSF but holds good in general as well. Key thing is that if you use the namespace from the implementation JAR then you will never run into issues.

Phantom answered 25/5, 2018 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.