任何人都可以在部署在Adobe CQ 5.6上的JSP中提供访问EL功能的指导吗?
我的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函数的调用失败。
错误如下: 文件“/ 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
}
}
public class UtilityFunction {
private UtilityFunction() {
...
}
public static String displayBuildNumber() {
// Do processing
}
}
<小时/> TLD,位于相同的OSGi包中,
src/main/resources/META-INF/utilityExpressionLanguageFunctions.tld
<小时/> JSP,位于
<?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>
:
/apps/myproj/components/page/main/head.jsp
答案 0 :(得分: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"%>
希望能解决问题