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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:52:46+00:00 2026-05-29T11:52:46+00:00

I am pretty new to Wicket and i have some difficulties with using resource

  • 0

I am pretty new to Wicket and i have some difficulties with using resource references. I am using wicket 1.5.4 and have following problem: I store images on the file system. I have class ImageElement which holds part of the file path relative to configured rootFilePath (i.e dir1/dir2/img1.png). On the page I add Image as follows:

new Image("id",ImagesResourceReference.get(), pageParameters)

where page parameters includes image path parameter (path=”/dir1/dir2/img1.png”). My questions are:

  • Is it the simplest way of serving images from the file system?
  • Is it ok to use ResourceReference with static method? or I should construct each time new ResourceReference? I saw that in previous version it was possible to use new ResourceReference(globalId), but it seems not to be the case anymore. If so what is the global resource reference for? So far as I understand resource reference is supposed to be factory for resources so it would be rather strange to create new factory for each resource request.
  • The last question is, how can i pass the path to the image in a better way so that i do not have to concatenate indexed parameters to build the path once respond method is invoked on ImageResource.
  • What would be the best scenario to get it working in efficient and simple way, i saw the example in ‘Wicket in action’, but this is meant for dynamic image generation from db and am not sure if it suites for my case

My implementation of ResourceReference which I mounted in Application under “/images” path, looks as follows:

public class ImagesResourceReference extends ResourceReference {

private static String rootFileDirectory;

private static ImagesResourceReference instance;

private ImagesResourceReference() {
    super(ImagesResourceReference.class, "imagesResourcesReference");
}

public static ImagesResourceReference get() {
    if(instance == null) {
        if(StringUtils.isNotBlank(rootFileDirectory)) {
            instance = new ImagesResourceReference();
        } else {
            throw new IllegalStateException("Parameter configuring root directory " +
                    "where images are saved is not set");
        }
    }
    return instance;
}

public static void setRootFileDirectory(String rootFileDirectory) {
    ImagesResourceReference.rootFileDirectory = rootFileDirectory;
}

private static final long serialVersionUID = 1L;

@Override
public IResource getResource() {

    return new ImageResource(rootFileDirectory);
}

private static class ImageResource implements IResource {

    private static final long serialVersionUID = 1L;

    private final String rootFileDirectory;

    public ImageResource(String rootFileDirectory) {
        this.rootFileDirectory = rootFileDirectory;
    }

    @Override
    public void respond(Attributes attributes) {

         PageParameters parameters = attributes.getParameters();
         List<String> indexedParams = getAllIndexedParameters(parameters);
         if(!indexedParams.isEmpty() && isValidImagePath(indexedParams)) {
             String pathToRequestedImage = getImagePath(indexedParams);
             FileResourceStream fileResourceStream = new FileResourceStream(new File(pathToRequestedImage));
             ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
             resource.respond(attributes);
         }
    }

    private boolean isValidImagePath(List<String> indexedParams) {
        String fileName = indexedParams.get(indexedParams.size() -1);
        return !FilenameUtils.getExtension(fileName).isEmpty();
    }

    private List<String> getAllIndexedParameters(PageParameters parameters) {
        int indexedparamCount = parameters.getIndexedCount();
        List<String> indexedParameters = new ArrayList<String>();
        for(int i=0; i<indexedparamCount ;i++) {
            indexedParameters.add(parameters.get(i).toString());
        }
        return indexedParameters;
    }

    private String getImagePath(List<String> indexedParams) {
        return rootFileDirectory + File.separator + StringUtils.join(indexedParams, File.separator);
    }

}

Any help and advices appreciated! Thanks in advance.

  • 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-29T11:52:47+00:00Added an answer on May 29, 2026 at 11:52 am

    You could use it as a shared resource:

        public class WicketApplication extends WebApplication {
            @Override
            public Class<HomePage> getHomePage() {
                return HomePage.class;
            }
            @Override
            public void init() {
                super.init();
                getSharedResources().add("downloads", new FolderContentResource(new File("C:\\Users\\ronald.tetsuo\\Downloads")));
                mountResource("downloads", new SharedResourceReference("downloads"));
            }
            static class FolderContentResource implements IResource {
                private final File rootFolder;
                public FolderContentResource(File rootFolder) {
                    this.rootFolder = rootFolder;
                }
                public void respond(Attributes attributes) {
                    PageParameters parameters = attributes.getParameters();
                    String fileName = parameters.get(0).toString();
                    File file = new File(rootFolder, fileName);
                    FileResourceStream fileResourceStream = new FileResourceStream(file);
                    ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
                    resource.respond(attributes);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using wicket 1.4.x for some time and solution found here worked pretty
Pretty new to C++, I have been following the intermediate tutorials at 3DBuzz.com, and
I am pretty new to php, but I am learning! I have a simple
I'm pretty new to regular expressions. I have a requirement to replace spaces in
Im pretty new to coding, heres my problem. Results->Text = G55 > Y +
I am pretty new to Java, so I may be using incorrect terminology. I
I am pretty new to image capturing using java. Just started working in java.
Pretty new to sqlite (and sql). Trying to modify one table using another. create
Pretty new to the Magento e-commerce solution. Have it up and running for a
still pretty new to android I have to clone an iphone application. Im having

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.