1

Hi Stackoverflow community,

I am using Wildfly 16 with on Java11 with JSF/Primefaces.

While using includes in .xhtml sources, I noticed that the case sensitivity of the path "xyz/abc.xhtml" in this construct is operating system dependent:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:include src="xyz/abc.xhtml"/>

Meaning, if the file is named Abc.xhtml, this will work on Windows but not on Linux where the filesystem is case sensitive.

Now I would like to assure the same behavoir on Windows and Linux.

Is is possible to configure JSF in a way so that the file access will be either case sensitive or case insensitive on both OS?

Thomas
  • 620
  • 7
  • 19
  • Can you please specify more clearly what you're wanting, so I can improve my answer. – fuggerjaki61 Nov 02 '20 at 13:06
  • Well, I didnt downvote yout answer, but I can see the point in it. You provided a workaround, thank you for that. But that was not the question. The question was how to make the server (or tech stack) behave the same way on Windows and on Linux. See the last sentence in my original question. To be more specific: please assume that I have no control over the referenced files, so other people may not follow the convention to use only lowercase filenames. May it be intentionally or by mistake. – Thomas Nov 05 '20 at 13:09
  • Please note, that I asked if this is possible. If it is not possible, it would be a perfectly good answer to say so with a short explanation. – Thomas Nov 05 '20 at 13:16

1 Answers1

-1

Solution

I think the best way to solve this is to name every file only with lower case letters and the references will be converted to lower case.


First create a class that will include a toLowerCase(String) method.

public final class Functions {

    private Functions() {
        // Hide constructor.
    }

    public static String toLowerCase(String s) {
        return s.toLowerCase();
    }
}

Then you have to define a functions.taglib.xml (functions is an example how to name it).

<?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>

The last step is to register the taglib in your web.xml.

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>

Now you're ready to use it:

<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>

Explanation

Basically this example will convert the source reference to lower case. This only works if you're files are also all named with lower case characters.

If defining a custom tag library is too time-consuming for you, you can also use a @ApplicationScoped bean and add the method there (see Utility methods in application scoped bean)

Of course, capatalizing the first letter of the filename works as well as lower case filenames. You just have to use a capitalize() method (I can add that on request or see How to capitalize the first letter of a String in Java?).

There may be other approaches but they will be a lot harder than this.


See Also

How to create a custom EL function to invoke a static method? (credit for the function definition)

Why are files case (in)sensitive on Linux and Windows?

fuggerjaki61
  • 822
  • 1
  • 11
  • 24