任何人都可以提供从部署在 Adobe CQ 5.6 上的 JSP 中访问 EL 功能的指导吗?
我的 JSP 位于一个包中,而我的 EL 函数(Java 类中的静态方法)和关联的 TLD 位于一个单独的 OSGi 包中。两者都安装到 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 函数的调用会失败。
错误显示: 找不到文件“/apps/aib/mortgage/components/page/main/utilityFunction”
我的代码如下。感谢所有帮助。
问候,肯。
EL 函数类,位于 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 />