问题
I'm roughly following this guide for creating composite components in JSF 2.2. I've managed to define and use a component, but I'm having problems properly organizing the components. In all tutorials the components are put into one directory and the files' names define the tag name.
META-INF/resources/ts
+-plainbox.xhtml
+-showcasebox.xhtml
I'd prefer having categories and a directory for each element, with bundled JS, CSS and images. I'd like to use a structure like this:
META-INF/resources/ts
+-containers
| +-plainbox
| | +-plainbox.xhtml
| | +-plainbox.css
| +-showcasebox
| +-showcasebox.xhtml
| +-showcasebox.js
+-otherstuff
+-...
Unfortunately, when using this structure I need to reference each component by an own namespace:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ts="http://java.sun.com/jsf/composite/ts/containers/showcasebox"
xmlns:ts2="http://java.sun.com/jsf/composite/ts/containers/plainbox">
<head jsf:id="head">
</head>
<body>
<ts:showcasebox>hello world</ts:showcasebox>
<ts2:plainbox>foo bar</ts2:plainbox>
</body>
</html>
Having to reference the categories one by one would be okay, but having a new namespace for each component is unbearable. Also I've read that this nesting is against the specification.
Is it possible to have a hierarchy of composite components in JSF with only one namespace? How are frameworks like Primefaces doing it? Are they defining all elements in Java?
来源:https://stackoverflow.com/questions/39537911/putting-jsf-composite-components-in-a-subfolder-based-hierarchy