Using custom JavaScript for AJAX with WebWork2

WebWork2 contains ftl and js files inside the webwork JAR and these two types of files make up a template for a theme. Anyways, customizing the ftl files is covered in the wiki but making custom js files is not covered. I figured out how to do this though by walking through the WebWork2 filter code. Here’s the quick solution:

If the the resource is (for example)

/webwork/ajax/validation.js

place your custom version into

WEB-INF/classes/template/ajax/validation.js

Really quick, here’s why. WebWork is lopping off the /webwork part of the URI and then adding a bunch of different prefixes until it finds the resource in the classpath (using ClassLoader.getResourceAsStream). The first one is some crazy package name like com/opensymphony/webwork or something. The next one is just template. Therefore, placing just about any static resource like JavaScript files in the WEB-INF/classes/template directory will allow WebWork to locate them.

This entry was posted in Java. Bookmark the permalink.

One Response to Using custom JavaScript for AJAX with WebWork2

  1. felix says:

    Thanks, in my installation the server cannot find some static files. this may be a workaround….

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>