1

In my application I mount following URL:

this.mountPage("/details/${site}", MerchantDetailPage.class);

So a request to for instance ../details/anything will create an instance of MerchantDetailPage with pageparameter: site=anything.

The constructor of MerchantDetailPage:

public MerchantDetail(final PageParameters parameters) {
    super();

    org.apache.wicket.util.string.StringValue storeParameter = parameters.get("site");
    if (!storeParameter.isEmpty()) {
        this.store = this.service.getStoreByQBonSiteWithCategoriesDescriptionsRegionAndAddress(storeParameter.toString());
    }

    if (store == null) {
        throw new RestartResponseAtInterceptPageException(Application.get().getHomePage());
    }

    // Build the page
    this.createPage(this.store, null);
}

This seemed to work fine until I noticed that the constructor was called 4 times. After some digging I found that the constructor was called once with parameter site=anything but then another 3 times for 3 images that are on the page; e.g.:

<img wicket:id="store_no_image" src="./images/shop_no_logo_big.png" alt="logo" />

So, for this resource Wicket is also calling this page but with parameter: site=images.

As a consequence, the store is null so the request for the image is redirected to the homepage => the image is not found.

Why is this happening? Why is wicket trying to treat a resource request through a page mount?

Some side comments:

  • MerchantDetailPage has also another constructor which is called directly from the code and accepts the store id as a parameter. In this case the problem does not occur.
  • if I use an absolute URL for the image it does work (does not enter into MerchantDetailPage for the image request)
Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101

1 Answers1

2

Well... your page resides at

/detail/anything

which is correctly mapped to your merchant detail page...

Your images reside at

/detail/images/shop_no_logo_big.png

and similar, which is correctly mapped to your merchant detail page... The mount path doesn't know and doesn't care if it's a page request or a resource request. For all it is worth it could be the case that you're using the mount path to create the resource dynamically...

So the solution is to move your images to a location that doesn't match yout mount-path.

Nicktar
  • 5,548
  • 1
  • 28
  • 43
  • Tx, but not sure how to go about that. The image in my post is in `webapp/images` and hence referenced as `./images/shop_no_logo_big.png`, so relative. So where to move it to? I could solve the issue for this image by using a wicket Image component for it (so no longer in the markup). The other 2 images however are referenced in JavaScript (Google map marker images) so I can't use the same approach there. Currently I worked around it by calculating (in JavaScript) the absolute URL of the marker image. This works (not sure why however) but I consider this a dirty and temporary workaround. – Stijn Geukens May 13 '13 at 10:42
  • If your images are in `webapp/images`, then the relative link is wrong since it's relative to `/detail/anything`. – Nicktar May 13 '13 at 11:20
  • What do you mean exactly? `` displays the image correctly so that path is ok. For me, the problem here is that Wicket is going to look for `/detail/images/shop_no_logo_big.png`. – Stijn Geukens May 13 '13 at 11:38
  • It shows the image corretly when called from which baseurl? Wicket isn't looking for `/details/images/and_so_on`. The Browser is because the browser is accessing the `anything` resource located at `/details` and you told it to look for the images at `dot/images/imagename`, meaning `wherever_you_are_right_now/images/imagename`. – Nicktar May 13 '13 at 12:25
  • OK, I think I understand what you mean now. I'll experiment a bit this evening... – Stijn Geukens May 13 '13 at 13:04
  • Implemented following solution for the JS-images: http://stackoverflow.com/a/2188506/190596 – Stijn Geukens May 14 '13 at 19:38