Modify Where Wicket Loads HTML Templates

by kinabalu on July 19, 2009

In Apache Wicket, the framework expects the HTML templates to mirror the class-file directory structure. The example below allows you to define a different path for your HTML files.

public class PathStripperLocator extends ResourceStreamLocator {
 
    public PathStripperLocator() {
    }
 
    public IResourceStream locate(final Class clazz, final String path) {
        IResourceStream located = super.locate(clazz, trimFolders(path));
        if (located != null) {
            return located;
        }
        return super.locate(clazz, path);
    }
 
    private String trimFolders(String path) {
        return path.substring(path.lastIndexOf("/") + 1);
    }
}
public class MyApplication extends AuthDataApplication {
    @Override
    protected void init() {
        super.init();
        IResourceSettings resourceSettings = getResourceSettings();
        resourceSettings.addResourceFolder("src/main/webapp"); //this path should be changed
        resourceSettings.setResourceStreamLocator(new PathStripperLocator());
    }

(via wicket wiki)

Similar Posts:

Share this:
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Slashdot
  • Technorati

{ 2 comments… read them below or add one }

Daniele DellafioreNo Gravatar March 12, 2010 at 11:25 am

Any idea about how to achieve this also for css or other files stored under src/main/resources/com/myapp/… ?

JorgeNo Gravatar June 3, 2010 at 9:12 am

This could help …

WebApplicationPath paths = new WebApplicationPath(getServletContext());
paths.add(“”);
paths.add(“/html”);
paths.add(“/images”);
paths.add(“/js”);
paths.add(“/styles”);
getResourceSettings().setResourceStreamLocator(new ResourceStreamLocator(paths));

Leave a Comment

Previous post:

Next post: