Package JSF Composite Component into JAR
Asked Answered
F

1

5

When attempting to bundle our composite components into a jar and include as a dependency in another project, I followed the following answer.

This works for everything except the composite component implementation. The folder structure for our common project is shown below:

CommonWebProject
 |-- META-INF
 |    |-- resources
 |    |    `-- common
 |    |         |-- css
 |    |         |    ...
 |    |         |-- js
 |    |         |    ...
 |    |         |-- components
 |    |         |    `-- comment.xhtml
 |    |         |-- templates
 |    |         |    `-- defaultTemplate.xhtml
 |    |-- faces-config.xml
 |    `-- MANIFEST.MF
 :

comment.xhtml consists of:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<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" xmlns:p="http://primefaces.org/ui" xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>

</composite:interface>

<composite:implementation>
  <p>TESTING!</p>
</composite:implementation>

</html> 

The actual implementation looks like:

<?xml version="1.0" encoding="UTF-8" ?>
  <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:csxc="http://java.sun.com/jsf/composite/csxcomponent" xmlns:p="http://primefaces.org/ui"
    xmlns:common="http://java.sun.com/jsf/composite/common"
    template="/common/templates/defaultTemplate.xhtml">
    <ui:define name="head">
    </ui:define>

    <common:comment/>

  </ui:composition> 

Here the template "defaultTemplate.xhtml" that is being pulled from the common jar is working correctly, but not the tag. Inspecting the page just shows the tag.

enter image description here

Any ideas why?

Frerichs answered 30/1, 2018 at 18:31 Comment(1)
Does it work when you include all in your project directly? Anything special in your faces-config.xml? Anything special in your web.xml? Versions?Lobachevsky
F
7
CommonWebProject
 |-- META-INF
 |    |-- resources
 |    |    `-- common
 |    |         |-- components
 |    |         |    `-- comment.xhtml
 :    :         :

Thus, the resource-relative path is /common/components/comment.xhtml.

However,

xmlns:common="http://java.sun.com/jsf/composite/common"
...
<common:comment />

the XML namespace basically says that comment.xhtml is inside /common folder. It's actually not there. It's actually inside /common/components folder.

Align out it.

xmlns:common="http://java.sun.com/jsf/composite/common/components"
...
<common:comment />

I have in the meanwhile fixed the answer you found there.

Full answered 31/1, 2018 at 7:38 Comment(3)
Ok great! I've got that working. If I wanted to include java classes would they fall under the 'components' folder as well?Frerichs
@Full Congratulation on becoming 2nd top user on Stackoverflow. You really deserve it.Trailer
@Eng.Fouad: Thanks :)Full

© 2022 - 2024 — McMap. All rights reserved.