Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3310804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:48:08+00:00 2026-05-17T21:48:08+00:00

I am building a site in Wicket. I need to serve a JavaScript file,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:48:09+00:00Added an answer on May 17, 2026 at 9:48 pm

    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 in WicketApplication by adding:

    String resourceKey = "DYN_RES_KEY";
    //load your text template
    final TextTemplate textTemplate = new PackagedTextTemplate(MyPage.class, "script.js", "text/javascript", "UTF-8");
    //add the resource
    getSharedResources().add(resourceKey, new Resource() {
        @Override
        public IResourceStream getResourceStream() {
            String queryParam = getParameters().getString("paramName");
            //...do whatever you need with the parameters...
            Map<String,Object> vars = new HashMap<String,Object>();
            vars.put("param", queryParam);
            String stringValue = textTemplate.asString(vars);
            return new StringResourceStream(stringValue, textTemplate.getContentType());
        }
    });
    //mount the resource at some public URL
    mountSharedResource("/resource", Application.class.getName() + "/" + resourceKey);
    //make alias, optional
    getSharedResources().putClassAlias(MyPage.class, "scripts");
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a site that will link to various other sites using php scripts
I am building a site that uses a simple AJAX Servlet to talk JMS
I'm building a site that's sort of a cross between StackOverflow and Digg (only
I'm building a new web application that uses Linux, Apache, Tomcat, Wicket, JPA/Hibernate, and
building a site using PHP and MySQL that needs to store a lot of
I'm building a site that requires multiple forms for the same model in varying
I'm building a site right now, so far I've painfully forced everything to be
I am building a site in asp.net and have multiple subdomains. For example, one.cookies.com
I am building a site and I have a list of status updates and
Ok. So I'm building this site which is accessible through two different domains. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.