2013-10-07 49 views
1

任何人都可以提供從Adobe CQ 5.6上部署的JSP中訪問EL功能的指導嗎?訪問Adobe CQ 5.6中的EL功能,未找到TLD

我的JSP位於一個包中,而我有EL函數(Java類中的靜態方法)和位於單獨的OSGi包中的關聯TLD。兩者都安裝到Adobe CQ。 捆綁包的POM做出口相關的Java包:

<plugin> 
    <groupId>org.apache.felix</groupId> 
    <artifactId>maven-bundle-plugin</artifactId> 
    <extensions>true</extensions> 
    <configuration> 
     <instructions> 
      <Bundle-Name>AIB UI Bundle</Bundle-Name> 
      <Export-Package> 
       mypackage.* 
      </Export-Package> 
      <Include-Resource> 
       {maven-resources} 
      </Include-Resource> 
      <Embed-Dependency>joda-convert;scope=compile|runtime,joda-time;scope=compile|runtime,</Embed-Dependency> 
      <Bundle-Resource>/META-INF/tags</Bundle-Resource> 
      <Sling-Bundle-Resource>/META-INF/tags</Sling-Bundle-Resource> 
     </instructions> 
    </configuration> 
</plugin> 

然而,當JSP被處理時,調用EL函數失敗。

錯誤讀取: 文件 「/應用/ AIB /貸款/組件/頁/主/ utilityFunction」 找不到


我的代碼如下。感謝所有的幫助。

Regards, Ken。

EL Function類,位於OSGi包,src/main/java/mypackage/UtilityFunction.java

package mypackage;

public class UtilityFunction { 

private UtilityFunction() { 
... 
} 

    public static String displayBuildNumber() { 
    // Do processing 
    } 
} 


TLD,位於同一OSGi包, src/main/resources/META-INF/utilityExpressionLanguageFunctions.tld

<?xml version="1.0" encodeing="ISO-8859-1" ?> 
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" 
version="2.0"> 
<tlib-version>1.0</tlib-version> 
<uri>utilityFunction</uri> 
<function> 
<name>displayBuildNumber</name> 
<function-class>mypackage.UtilityFunction</function-class> 
<function-signature>String displayBuildNumber()</function-signature> 
</function> 
</taglib> 


JSP,位於 /apps/myproj/components/page/main/head.jsp

<%@include file="/libs/foundation/global.jsp"%><% 
%><%@page session="false" %> 
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %> 
<%@taglib prefix="utils" uri="utilityFunction" %> 

<head> 
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
<meta http-equiv="keywords" content="<%=properties.get("p_metaKeywords","") %>" /> 
<meta name="description" content="<%=properties.get("p_metaDescription","") %>" /> 
<meta http-equiv="X-UA-Compatible" content="IE=8" /> 

<title>My Application ${utils:displayBuildNumber()}</title> 
<cq:include script="/libs/wcm/core/components/init/init.jsp"/> 
<cq:include script="/libs/wcm/core/browsermap/browsermap.jsp" /> 
<cq:includeClientLib css="jquery-ui" /> 
<cq:includeClientLib js="cq.jquery, cq.foundation-main, cq.shared, forms-overlay, jquery-ui,cq.jquery.ui" /> 
</head> 

<cq:defineObjects /> 
+0

如果問題不在你的軟件包安裝,我認爲uri可能需要更像這個''<%@ taglib prefix =「ex」uri =「WEB-INF/custom.tld」%>' – bfitzpatrick

回答

1

您需要有一個uri值的完整地址。請看下面的全功能例如:

//在pom.xml

<plugin> 
<groupId>org.apache.felix</groupId> 
<artifactId>maven-bundle-plugin</artifactId> 
<extensions>true</extensions> 
    <configuration> 
     <instructions> 
      <Export-Package> 
      //Packages..... 
      </Export-Package> 
      <Import-Package> 
      *;resolution:=optional 
      </Import-Package> 
      <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
      <Sling-Test-Regexp>.*Test</Sling-Test-Regexp> 
      <Include-Resource> 
       META-INF/my-tags.tld=target/classes/META-INF/my-tags.tld 
      </Include-Resource> 
     </instructions> 
    </configuration> 
</plugin> 

//在TLD文件中

<description>My Test Taglib</description> 
<tlib-version>1.0</tlib-version> 
<short-name>cq-common</short-name> 
<uri>http://taglib.cq.mycompany.se/taglibs/my-tags/1.0</uri> 

<function> 
    <name>doSomeThing</name> 
    <function-class>com.my.company.SomeUtils</function-class> 
    <function-signature>String doSomeThing(java.lang.String)</function-signature> 
</function> 

//在JSP文件

<%@taglib prefix="mytags" uri="http://taglib.cq.mycompany.se/taglibs/my-tags/1.0"%> 
${mytags:doSomeThing(stringValueOfSomething)} 

通知位於一個完全合格的地址在兩個地方的URI值: 在TLD文件:

<uri>http://taglib.cq.mycompany.se/taglibs/my-tags/1.0</uri> 

,並在jsp文件:

<%@taglib prefix="mytags" uri="http://taglib.cq.mycompany.se/taglibs/my-tags/1.0"%> 

希望這將解決這個問題