我如何从OSGi中的不同xhtml(另一个包)调用jsf模板

时间:2015-04-21 07:47:15

标签: maven jsf templates osgi apache-karaf

我想从另一个xhtml调用xhtml模板但是这个xhtml在不同的项目中(不同的jar)。我正在使用OSGi和karaf。

这是我的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>

这个jar没有测试包。这个包在我的另一个罐子里。主jar的文件夹结构是;

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

模板jar的文件夹结构是;

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

最后一个我的template.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: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>

当然,我添加到模板jar的pom.xml;

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

掌握jar的pom.xml;

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

但我运行该项目,我收到了这个错误;

/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 个答案:

没有答案