문제

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)
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top