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 9137047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:02:31+00:00 2026-06-17T09:02:31+00:00

I am displaying a static image asset inside a component, and I don’t know

  • 0

I am displaying a static image asset inside a component, and I don’t know until runtime what that image should be, so I need to dynamically generate the URL. These images all live in webapp/images/

The documentation I found is not very clear on how to handle this usecase, but after playing around I figured out I can construct the URL dynamically in the component template like so:

<img src="${context:img/score/overall}/${imageFilename}" />

Then put the logic for which image to display in the component class file:

public String getImageFilename() {
    // decide which image to display and return the filename
}

So this works, but it’s not the cleanest solution. I don’t really want to concatenate the URL base to the filename inside the template – I’d much rather construct the entire URL in the component class, like so:

<img src="${imageUrl}" />

and

public String getImageURL() {
    // build URL somehow like "context:" + "filePath" in template
}

So my question is: Is there a Java code equivalent of context: ... in the template that simply produces a String base URL for the web appl context folder that I can append my file path to?

I can see some obvious hacky ways of doing it from reading the docs, like manually constructing the base URL using the scheme described, or injecting a known static image as an Asset from the web app context folder and calling toClientURL() to extract the base URL. But it seems like there must be a nice built-in way to do this in Java, especially since it’s freely available to use in a template expansion.

But google as I might, I can’t seem to find how to do this anywhere!

  • 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-06-17T09:02:32+00:00Added an answer on June 17, 2026 at 9:02 am

    I think this should do the trick for you. (disclaimer: I have not tested it)

    @Inject
    private AssetSource assetSource;
    
    @Inject
    private Locale locale;
    
    public String getImageURL() {
        URL assetUrl = assetSource.getContextAsset("img/score/overall/" + getImageFilename(), locale).toURL();
        return assetUrl.toString();
    }
    

    Edit: Updated to reflect Howards comment

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

Sidebar

Related Questions

What I have is a static website that should provide displaying a local image
I need to give functionality to user of cropping the image. I am displaying
Displaying Type here to ... until the user enters text into a TextBox is
Given the image url, I need to download it and display in an ImageView.
I have problem with displaying bitmap image on imageview on high density screen (480x800).
I have a table view with 10 cells displaying an image. Everytime I scroll,
I am suing Listview and customize listview to display image inside a list item.
In my app i am displaying images 1 after other for 1 second.In that
I am working on a quiz application. In that I am displaying the question
I previously worked on fetching image from sd card displaying it in a list

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.