User Defined XMLNS in Primefaces (xhtml) - jsf

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/

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

How to render XML from a JSF 2.0 page

I'd like to build VXML using JSF2.0 but I didn't find any supporting tags. What we've proposed is writing xhtml pages with vxml data (having references to backing bean where ever value needs to get replaced) by having content type as 'text/xml' so client can read the xml directly.
<html 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">
<f:view contentType="text/xml">
<vxml>
<log>Caught the event </log>
<prompt bargein="true">
<audio src="built-in: #{myBackingBean.prompt}" />
</prompt>
</vxml>
</f:view>
</html>
But when ever I try to launch above xhtml page in a browser or using a REST webservice client -
1) I'm not seeing xml returned. But just Caught the event as output in browser. REST client is not seeing any output.
2) myBackingBean.prompt value is not getting replaced
Can any one suggest please? We do not want to use plain old servlets to construct the xml. We'd like to write XML manually but need values to be replaced from backing bean.

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:

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