Where can I find XML schema definitions (XSD) for JSF Facelets tag libraries? - jsf

Where can I find XML schema definitions for
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
or since JSF 2.2
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
?

I recently found puzzling lack of XSD for JSF tags. Although such XSD would not be complete reference as described here I find it still useful. They can help avoid typos and provide documentation for tags and attributes.
Therefore I transformed available taglib.xml files to XSD files. The result is available on my GitHub project. Available XSLT transform can be used to generate XSD from any *.taglib.xml file.
In IntelliJ IDEA Community those XSDs work like a charm.

In the jar-file of your JSF implementation there is a META-INF folder. There you can find the .tld files that you need. But they are not .xsd.
Note that if you are using facelets, the facelets definitions are in the jsf-facelets-xx.jar
As for the JSTL core tags - this is a useful reference
That is all about JSF pre-2.0.

You can convert the .tld files from #Bozho's answer to XSD files to integrate into an Schema Aware XML Editor Details
If you happen to use IntelliJ, you can add the JSF facet to your module, and the IDE will provide autocomplete and documentation for elements and attributes in the JSF namespaces, based directly on the .tld files.

Related

jsf - facelets - pack library jar with *.xhtml-s and beans only

I could read the tutorial which describes how to pack facelets to jar to reuse tags as library...
The thing is the instruction recommends using both JSP and JSF in manner as (see code snippet);
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
<ui:composition>
...
</ui:composition>
</jsp:root>
...and using both .taglib.xml + .tld conf files... :(
So I don't get it may ui:composition in *.xhtml be started as usual by (see code snippet) ...
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
...
</ui:composition>
...not to deal with jsp at all? And if, yes, how this kind of library can be added to dynamic web project in eclipse for example?
So my question concerning the tutorial is...
A) is there a way to avoid using *.tld and use have *.taglib.xml only for the lib if the tag library will contain xhtml files only?
B) is there a way to have xhtml-s in non META-INF sub-folder but in some random one?
C) How to automate this kind of library creation process? I mean should I create a project in eclipse (?project category) to have correct folders structure by default to make possible re-compile it and test it and only after that pack it as a jsf library?
I googled a lot but couldn't find solutions variations so please share your experience;
Thanks

Why JSF needs XHTML instead of HTML? [duplicate]

Facelets relies on XML namespaces to work with XHTML. How are HTML 4, and as far as I know, HTML 5 do not support namespaces. Also HTML 5 has some new elements that are not available in XHTML. Even HTML 4 and XHTML have some differences regarding elements and attributes they support.
The question is: Is it possible to render HTML 4/5 documents using Facelets? If so, how?
Since Facelets is a XML based view technology which eats and emits in essence XML markup, you cannot use it with a HTML4 doctype. The HTML4 doctype describes several elements which cannot be self-closing, like <link>, <meta>, <br> and <hr>. However, with XML you're forced to close them like <link/>, <meta/>, etc. So using a HTML4 doctype is absolutely not an option for Facelets (that is, when you respect the standards and/or fear the w3 validator, it will however work perfectly on the most if not all webbrowsers).
HTML5, on the other hand, allows XML markup. This is specified in chapter 3.2.2 - Elements:
Example:
<link type="text/css" href="style.css"/>
Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include whitespace before the slash, however this is not necessary. (Using whitespace in that fashion is a convention inherited from the compatibility guidelines in XHTML 1.0, Appendix C.)
I myself use <!DOCTYPE html> all the way, also with JSF/Facelets, even without a <?xml?> declaration in top of the page. It works perfectly in all browsers. With a XHTML doctype you should as per the specification be using a Content-Type of application/xhtml+xml which would only make MSIE to choke (it doesn't understand it). And since that's still one of the most widely used browsers... Replacing the XHTML content type by text/html is considered harmful, you also don't want to do this.
As per your arguments:
HTML 5 do not support namespaces.
This doesn't matter. The namespaces are only of interest for the XML based server side view technology (like as Facelets) which in turn can generate pure HTML with those tags. The following example is legitimately valid for Facelets:
<!DOCTYPE html>
<html lang="en"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Title</title>
</h:head>
<h:body>
<h:outputText value="#{bean.text}" />
</h:body>
</html>
This renders legitimately valid HTML5 (for the client side):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
Some text
</body>
</html>
You see, Facelets already removes the XHTML declarations since they have no meaning in the client side.
And,
Also HTML 5 has some new elements that are not available in XHTML
this make also no sense. It's all about the generated output. Which can be HTML5 as good. Your only problem may be the browser support and the availability of 3rd party JSF components which renders HTML5 specific elements. Since JSF 2.2, it's possible to use the new passthrough elements feature to turn custom elements into a JSF component. Simply give the HTML5 element a jsf:id attribute. It'll transparently internally be interpreted as a UIPanel instance in the JSF component tree (like <h:panelGroup>).
<!DOCTYPE html>
<html lang="en"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
>
<h:head>
<title>Title</title>
</h:head>
<h:body>
<header jsf:id="header">Header</header>
<nav jsf:id="nav">Nav</nav>
<main jsf:id="main">Main</main>
<footer jsf:id="footer">Footer</footer>
</h:body>
</html>
You can even reference it from ajax as in <f:ajax render="main">.
Actually, XHTML is overhyped. Its sole intent is to ease HTML development using XML based tools which can manipulate/transform/generate HTML pages on the server side (like as Facelets). But some starters also use it without using any XML tool and output it plain as-is, because it's "so cool" -for some unclear reason.
Don't get me wrong. XHTML is great as server side view technology. But simply not as client side markup technology. It has utterly no value at the client side.
See also:
Our XHTML wiki page
How should a <!DOCTYPE> section look in JSF? HTML5 or XHTML?
JavaServer Faces 2.2 and HTML5 support, why is XHTML still being used
On a related note, check out this IBM developerWorks article: JSF 2 fu: HTML5 composite components, Part 1
MyFaces has an extension for html5. Try this http://myfaces.apache.org/html5/
I've read, that this should be possible, but I did not do it myself, yet. Maybe you should just use HTML 5 inside the xHTML wrapper code. I will see, if I can find the source of information I've again.
[EDIT]
Seems like, there has been some work at MyFaces to support HTML5 rendering during Google's summer of code. I don't know if it should be used in a productive way, yet.
MyFaces Wiki
java-doc
Jazzon talk, download presentation
Jazzon talk, Exploring HTML 5 with JSF 2
Please give us a feedback, if you get it to work.
[/EDIT]
http://wiki.whatwg.org/wiki/HTML_vs._XHTML has some useful information on how namespaces can be used in HTML5 to assist migration from XHTML. Perhaps you can try applying the namespace as it suggests and see what occurs?

JSF 2.2 html5 friendly page

Some sources indicate that it's possible to use non-obtrusive jsf:id attributes in a JSF2.2 page.
https://weblogs.java.net/blog/edburns/archive/2012/11/01/html5-friendly-markup-jsf-22
http://www.apress.com/9781430244257
The taglib descriptors use different urls.
From the weblog:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://java.sun.com/jsf">
<head jsf:id="head">
From the book:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head jsf:id="head>
However, while using the newest JSF2.2 implementation (2.2.0-m15), both urls for the tag descriptors are unreachable (CANNOT_FIND_FACELET_TAGLIB), resulting in a partially unparsed html page.
Where to find the correct urls for the jsf tag library? Is there some kind of index for those urls?
To use jsf:id use http://xmlns.jcp.org/jsf namespace. This is applicable for form input. It is not used on head tag. For example, the following code declares the namespace with the short name jsf:
<html ... xmlns:jsf="http://xmlns.jcp.org/jsf"
...
<input type="email" jsf:id="email" name="email"
value="#{reservationBean.email}" required="required"/>
Here, the jsf prefix is placed on the id attribute so that the HTML5 input tag's attributes are treated as part of the Facelets page.
The latter is the correct definition. I don't think the head tag is used that way with JSF. Use the JSF html tag library.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<h:head></h:head>
....
You typically use jsf:id for HTML5 input components. Refer to the Java EE 7 Tutorial section on HTML5/JSF pass-through for information and an example application.

User Defined XMLNS in Primefaces (xhtml)

Can we include our own xml file in xmlns tag
Example: Consider a file "myxhtmlfile.xhtml ".. in this we could add xml namespaces like,
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:p="http://primefaces.org/ui"
and etc.. [Note:In primefaces.org/ui (consists of many .xml files)]
I've an xml file "myxmlfile.xml" in my system drive (say D:/ Drive) so, what is the approach do we need follow for adding my own xml files ("myxmlfile.xml") in the xhtml file.
There are some tags in myxmlfile.xml file, which i need to use just like 'p' tags (primefaces tags)
Eg: <p:messages id="messages" showDetail="true" autoUpdate="true"/>
My requirement is like :(I should be able to use all the tags that are defined in myxmlfile.xml) like,
<m:mymessages id="mymessages" showDetail="true" autoUpdate="true"/>
i've tried many methods like placing the both files together in same folder and adding this type of lines(xmlns:m="D:/resources/xml") in the xhtml file, but found no luck.
I'm using primefaces 3.2
Thanks in advance
What you are looking for is composite components.
Take a look at this blog : http://www.mkyong.com/jsf2/composite-components-in-jsf-2-0/

What's the difference between <h:head> and <head> in Java Facelets?

See this.
When and why to use <h:head>, instead of <head>?
I've seen Primefaces won't work with <head>, though.
The <h:head> is a JSF component which provides a hook to programmatically include JavaScript and CSS resources in the generated HTML <head>. PrimeFaces uses it to include the necessary JS/CSS code for the Ajax works and fancy look'n'feel.
As a test, create a page with a <h:head> and a PrimeFaces component, open the page in the webbrowser and check the generated HTML source by rightclick - View Source. You'll see that several JSF and PrimeFaces specific JS/CSS files are been added. Now replace <h:head> by <head> and check the generated HTML source once again, you'll see nothing this time.
The <head> tag is a HTML tag, which defines the head of the HTML page (this is where you define metadata, or include the resources such as JavaScript or CSS for example).
The <h:head> is a JSF tag (introduced with JSF 2.0) that handles the <head> part of your page. The interest of having such JSF tag is that this head becomes part of your JSF components tree, and thus, you can manipulate it in your Java code.
Regarding the <head> incompatibility with Primefaces, I don't see why it happens. Facelets introduced in JSF 1.x the ability to mix HTML code and JSF (XHTML) code, and you should not have any trouble to insert a HTML <head> tag in your page, even if you use Primefaces. Facelets is natively integrated with JSF 2.x.

Resources