Pages

Wednesday, July 24, 2013

I am really enjoying the new NetBeans 7.4 Beta. It features a new mechanism to add license headers to your project. It also allows you to switch the license easily in your project as well. In this example I will add a new BSD 3-Clause License "New BSD" to the Template Manager. This makes it easier to create a project using any variety of license that is required.

I have a great opportunity to do different things at work. I get to help solve some really interesting issues around web development. This is particularly true with JSF. In the last few days we have been working on some issues with WebSphere using JSF. In particular, there is an issue with Drag-and-Drop (DnD) on RichFaces with MyFaces on WebSphere. We figured out that there is a possible fix we can implement by fixing the RichFaces DnD Javascript library.

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

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 first thing you need is a static-resource-mappings.properties file. This tells the RichFacesResourceServlet what 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.js file to an alternative location on the file system. This alternative remapping of jquery.js file 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.