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

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

Related

Extract XML namespace declarations into separate tagfile/taglib

I would like to seperate my XML namespace declarations at the top of the page into a seperate (tag)file in which I can include in any Facelets page I wish.
Is this possible? Or do I need to copypaste all XML namespaces in each Facelets file?
Here's a theoretical example, xmlns.xhtml:
<something
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:c="http://java.sun.com/jsp/jstl/core"
...
/>
And the template file which could use it: mypage.xhtml:
<f:view xmlns="xmlns.xhtml">
<h:head>
...
</h:head>
<h:body>
...
</h:body>
</f:view>
Nope, not possible. They must be present during XML compile time already.
Your best bet is creating or configuring XHTML template(s) in your IDE so that you can choose from them in New File without the need to copypaste/retype the boilerplate.
Here are some screens from Eclipse + JBoss Tools:

PrimeFaces components don't appear in browser

I'm using JSF 2.2 in my Project (Tomcat 7.42, Mojarra 2.2.1), and i want to use p:calendar from PrimeFaces library. I have included primefaces-4.0.jar into my Project Libraries, and add xmlns:p="http://primefaces.org/ui" namespace, and everything looks ok. Here is my code:
<?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"
xmlns:p="http://primefaces.org/ui">
<h:body>
<p:calendar value="#{calendarBean.date2}" id="popupCal" />
</h:body>
</html>
But, in browser, calendar doesn't appear. Standard h: components work great, but from PrimeFaces - nothing works.
I know that PF 4.0 should support JSF 2.2, but i have some issue.
I appreciate any help?
In jsf 2.2 namespaces are changed so you shoud use xmlns.jcp.org instead of java.sun.com
I managed to solve the problem! I am really sorry, but a PrimeFaces' "Getting Started" really confused me. The problem is that I had added PrimeFaces as a library into build path of my project, which is not correct. The right way is to put primefaces-4.0.jar into lib folder under web project. Things are better now. Anyway, thanks people.

Implementing JSF Composite Component in Maven project

It seems people are able to implement composite components in SWF 2.3.1, but I cannot find a clear reference for how this is done. I have followed the basic structure for a JSF composite component, but my SWF application does not seem to recognize the taglib namespace.
There is a toolkit/IDE warning, but more importantly there is a runtime warning seen in the browser, JSF is displaying the following warning on the screen to the user:
Warning: This page calls for XML namespace http://java.sun.com/jsf/composite/myjsf declared with prefix mj but no taglibrary exists for that namespace.
Component definition:
src/main/resources/myjsf/testComponent.xhtml :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="attr" />
</composite:interface>
<composite:implementation>
#{cc.attrs.attr});
</composite:implementation>
</html>
Referenced in a given xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
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:p="http://primefaces.org/ui"
xmlns:mj="http://java.sun.com/jsf/composite/myjsf">
<!-- snip -->
<mj:testComponent attr="x" />
</ui:composition>
The folder src/main/resources/myjsf/ isn't right place for your composite component. Composite component in maven projects should be in src/main/webapp/resources/ and in your case it should be src/main/webapp/resources/myjsf/testComponent.xhtml.
As you are using Maven you should know that webapp folder is folder whose content will be deployed in root folder of your application, and thus it is somehow analogue as WebContent folder in standard dynamic web project in Eclipse.

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

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.

Include non-Facelet content in a Facelet template

Is there a way to have the content of an html file inserted into a Facelet template? The Facelets tag will not work since it is only for including Facelet content.
To put it another way, I am looking for the Facelets equivalent to the JSP include directive <%# include file="..." %>.
I may not understand what you need, but <ui:include> is not restricted to facelets content, you can insert valid xhtml with it, according to this link.
Consider following facelets file (test.jsp):
<!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:f="http://java.sun.com/jsf/core">
<body>
<f:view>
<h:outputText value="Text outside include"/>
<ui:include src="testinclude.html"/>
</f:view>
</body>
</html>
And following HTML file (testinclude.html):
<h2>Text from included page</h2>
It includes correctly the HTML content in the page. This also applies when using <ui:include> in a facelets template.
The only include mechanism in Facelets is , which doesn't allow arbitrary content to be included, only well formatted XML. There is no equivalent to the JSP include directive in Facelets.
Omnifaces's <o:resourceInclude> can be used to include arbitrary content directly to the response. Which means it doesn't have to be well formed xml as with <ui:include>. Also you can include content in <h:head> section of your JSF page, which is tough to achieve otherwise.
http://showcase.omnifaces.org/components/resourceInclude
This describes a solution to this: http://arjan-tijms.omnifaces.org/2010/04/facelets-and-legacy-jsp.html
The solution includes building a simple UI component that loads the JSP or Servlet content into a string and renders that via the normal response writer.

Resources