解决方案
我认为解决这个问题的最好方法是只用小写字母命名每个文件,并且引用将被转换为小写。
首先创建一个包含toLowerCase(String) 方法的类。
public final class Functions {
private Functions() {
// Hide constructor.
}
public static String toLowerCase(String s) {
return s.toLowerCase();
}
}
然后你必须定义一个functions.taglib.xml(functions 是一个如何命名的例子)。
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://example.com/functions</namespace>
<function>
<function-name>contains</function-name>
<function-class>com.example.Functions</function-class>
<function-signature>boolean contains(java.util.Collection, java.lang.Object)</function-signature>
</function>
</facelet-taglib>
最后一步是在 web.xml 中注册 taglib。
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>
现在您可以使用它了:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:fn="http://example.com/functions">
<ui:include src="fn:toLowerCase('xyz/Abc.xhtml')}"/>
</html>
说明
基本上这个例子会将源引用转换为小写。这仅适用于您的文件也都以小写字符命名的情况。
如果定义自定义标签库对您来说太耗时,您还可以使用@ApplicationScoped bean 并在其中添加方法(请参阅Utility methods in application scoped bean)
当然,将文件名的第一个字母大写也适用于小写文件名。您只需要使用capitalize() 方法(我可以根据要求添加该方法或查看How to capitalize the first letter of a String in Java?)。
可能还有其他方法,但它们会比这更难。
另见
How to create a custom EL function to invoke a static method?(函数定义的功劳)
Why are files case (in)sensitive on Linux and Windows?