how do i call jsf template from different xhtml (a

2019-08-08 01:54发布

I want to call xhtml template from another xhtml but this xhtml is in different project(different jar). I'm using OSGi with karaf.

This is my master.xhtml ;

<?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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
    <title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
    <ui:include src="/test/template.xhtml"></ui:include>
    <h:form>
        <h:panelGrid columns="2" cellpadding="5">
            <h:commandButton value="Welcome Me" action="welcome"></h:commandButton>
        </h:panelGrid>
    </h:form>
</h:body>
</html>

This jar hasn't test package. This package is in my another jar. Master jar's folder structure is ;

-src
    -main
        -webapp
              -WEB-INF
              -master.xhtml

And template jar's folder structure is ;

-src
    -main
         -resources
                  -test
                       -template.xhtml
                       -subtemplate.xhtml
         -webapp
               -WEB-INF

And the last one my template.xhtml is ;

<?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">

<h:head>
    <h:outputStylesheet name="common-style.css" library="css" />
</h:head>

<h:body>

    <div id="page">

        <div id="header">
            <ui:insert name="header">
                <ui:include src="subtemplate.xhtml" />
            </ui:insert>
        </div>

    </div>

</h:body>
</html>

And of course i add to template jar's pom.xml;

<Export-Package>
               test;version="1.0",
               *
</Export-Package>

And master jar's pom.xml ;

<Import-Package>
                .
                .
                .
                .
              test;version="[1.0.0,2.1)",
              *
</Import-Package>

But i run the project, i got this error ;

/test/template.xhtml Not Found in ExternalContext as a Resource

viewId=/master.xhtml
phaseId=RENDER_RESPONSE(6)

Caused by:
java.io.FileNotFoundException - /test/template.xhtml Not Found in ExternalContext as a Resource
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:280)

0条回答
登录 后发表回答