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.

One thought on “Using custom JavaScript for AJAX with WebWork2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s