My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

.

.

.

.

.

.

.

.


[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

luni, 15 iunie 2015

[OmniFaces utilities 2.1] Create a single XML Document based on given URLs representing XML documents


[OmniFaces utilities] The createDocument() method creates a single XML Document based on given URLs representing XML documents. All those XML documents are merged into a single root element named root.

Method:
Usage:

The Xml#createDocument() is based on Java, DocumentBuilderFactory, DocumentBuilder and Document API.
Let's suppose that you want to obtain the DOM of the web.xml file. For this, you can use the Xml#createDocument(), as below:

import org.omnifaces.util.Xml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
...
private static final String WEB_XML = "/WEB-INF/web.xml";
...
ServletContext servletContext = (ServletContext) Faces.getExternalContext().getContext();
List<URL> urls = new ArrayList<>();
urls.add(servletContext.getResource(WEB_XML));
      
try {
    Document document = Xml.createDocument(urls);
    // DOM available in memory
    // DOM root, Element root = document.getDocumentElement();
} catch (SAXException ex) {
    // ...
}

Let's suppose that you want to obtain the DOM of available faces-config.xml files. For this, you can use the Xml#createDocument(), as below:

import org.omnifaces.util.Xml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
...
private static final String APP_FACES_CONFIG_XML = "/WEB-INF/faces-config.xml";
private static final String LIB_FACES_CONFIG_XML = "META-INF/faces-config.xml";
...
ServletContext servletContext = (ServletContext) Faces.getExternalContext().getContext();
List<URL> urls = new ArrayList<>();
urls.add(servletContext.getResource(APP_FACES_CONFIG_XML));
urls.addAll(Collections.list(Thread.currentThread().getContextClassLoader().getResources(LIB_FACES_CONFIG_XML)));
            
try {
    Document document = Xml.createDocument(urls);
    // DOM available in memory
    // DOM root, Element root = document.getDocumentElement();
} catch (SAXException ex) {
    // ...
}

Sample of faces-config.xml that was merged:

D:/wildfly/standalone/deployments/Test_1-1.0-SNAPSHOT.war/WEB-INF/faces-config.xml

jar:file:/D:/wildfly/modules/system/layers/base/org/jboss/as/jsf-injection/main/wildfly-jsf-injection-8.2.0.Final.jar!/META-INF/faces-config.xml

vfs:/D:/wildfly/standalone/deployments/MoveComponent_1-1.0-SNAPSHOT.war/WEB-INF/lib/omnifaces-2.1.jar/META-INF/faces-config.xml

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors