So.... the question is how do we implement the changed library without having to compile a custom version of RichFaces, or modifying the files to load our changed script and prevent the bad script from loading, or implementing our own
Well there are a number of alternative solutions, but if you are using RichFaces there is a simple choice: using the Resource Mapping feature of RichFaces This feature allows you to remap resources to point to alternative resources. This is a really helpful and convenient feature, and solves our problem of modified DnD JS for our RichFaces application.
The details of how to use it are mentioned on the Resource Mapping page, but only from a very high level, and there is no example implementation. There is a blog post Re-routing JSF resource requests with RichFaces Resource Mapping from Lukas Fryc which details more functionality than the guide, but there is no complete example. I am going to rectify that with this post.
The code for the example that follows is located here: richfaces-resource-mapping.
The first thing you need is a static-resource-mappings.properties file. This tells the RichFaces
ResourceServletwhat the alternative mappings should be. In the example application above my mappings look like the following.
As you can see, I am remapping images to remote IP addresses, and the
jquery.jsfile to an alternative location on the file system. This alternative remapping of
jquery.jsfile allows us to replace the JQuery instance that comes with RichFaces with our own alternative version.
The static-resource-mappings.properties needs to be located in the META-INF/richfaces directory, or one of the other alternatives as noted in Resource Mapping guide. This can be easily accomplished in Maven using the code below:
This allows us to copy the files in the resources directory to META-INF/richfaces automatically while building.
That is pretty much it. How about that for being easy.
Here is what the output looks like in the example application: richfaces-resource-mapping.
|RichFaces Resource Mapping|