I am building a site in Wicket. I need to serve a JavaScript file, xyz.js, for other people/websites to read directly — that is, not to be included in one of my HTML pages.
xyz.js needs some dynamic contents based on the path_info that is provided to it during the request, so it needs to be a template that can be interpolated.
Is there a way for me to build and serve this JS file using Wicket?
If not, what is the best alternative solution? A JSP file?
EDIT: In my initial answer I overlooked the requirement to make this JavaScript file available from public URL. While researching for a way to to that, I realized that my whole approach was flawed. So, I move my original answer to the end and provide a more-to-the-point answer up here.
On order to publish a text resource on a public URL (JavaScript or CSS), you need to edit your
init()method inWicketApplicationby adding:DISCLAIMER: This code is not written in IDE and never ran. As such, it might not even compile. Still, it should be enough to illustrate the way this could be accomplished.
This answer is based on “Dynamically Generate a CSS Stylesheet” and “Wicket Dynamic Image URL“, see those sources for more details.
ORIGINAL ANSWER (useful if you want to add JavaScript or CSS as externally referenced file to your Wicket page, but not make it publicly visible):
Check out “Dynamically Generate a CSS Stylesheet” page in Wicket wiki and WICKET-2890 issue in JIRA. Since Wicket 1.4.10, the TextTemplateResourceReference class is now part of Wicket core, so you do not need to copy-paste it anymore.
The wiki page mentions CSS page, but the approach is the same for JavaScript or any other non-markup text content.