title: Wicket image component not found on page
body: <p>I get the following problem when trying to display a list of items. For each item, I have to display an image which is dynamically loaded via a Wicket <code>WebResource</code>. The items are loaded step by step &#8212; 50 at a time &#8212; upon user scrolling, using an Ajax scroll.</p>
  
  <blockquote>
    <p>[ERROR] 2011-04-19 09:58:18,000 btpool0-1  org.apache.wicket.RequestCycle.logRuntimeException (host=, request=, site=):
    org.apache.wicket.WicketRuntimeException: component documentList:scroller:batchElem:666:content:item:3:batchItemContent:linkToPreview:imageThumbnail not found on page com.webapp.document.pages.DocumentListPage[id = 1]
    listener interface = [RequestListenerInterface name=IResourceListener, method=public abstract void org.apache.wicket.IResourceListener.onResourceRequested()]</p>
    
    <p>org.apache.wicket.protocol.http.request.InvalidUrlException: org.apache.wicket.WicketRuntimeException: component documentList:scroller:batchElem:666:content:item:3:batchItemContent:linkToPreview:imageThumbnail
    not found on page com.webapp.document.pages.DocumentListPage[id = 1] listener interface = [RequestListenerInterface name=IResourceListener, method=public abstract void org.apache.wicket.IResourceListener.onResourceRequested()]
        at org.apache.wicket.protocol.http.WebRequestCycleProcessor.resolve(WebRequestCycleProcessor.java:262)
        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1310)
        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
        at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
        at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
        at org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.CGLIB$doGet$6()
        at org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816$$FastClassByGuice$$6d42bf5d.invoke()
        at com.google.inject.internal.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)
        at com.freiheit.monitoring.PerformanceMonitoringMethodInterceptor.invoke(PerformanceMonitoringMethodInterceptor.java:115)
        at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)
        at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:44)
        at org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.doGet()
        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
        at org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.CGLIB$doFilter$4()</p>
  </blockquote>
  
  <p>How can this problem be solved?</p>
  
  <p>Here is the part of the code responsible for adding the image:</p>
  
  <pre><code>previewLink.add(createThumbnailSmall("imageThumbnail", documentModel));
  </code></pre>
  
  <p>in</p>
  
  <pre><code>createThumbnailSmall(final String id, final IModel&lt;BaseDocument&gt; documentModel) {
      // thumbnailResource is an object that contains the path of the image
  
      if (thumbnailResource != null) {
          final WebResource resource = getWebResource(thumbnailResource);
          final Image image = new Image(id, resource);
          return image;
      }
      return new InvisibleContainer(id);
  }
  
  WebResource getWebResource(final DocumentResource documentResource) {
      return new WebResource() {
  
          private static final long serialVersionUID = 1L;
  
          @Override
          public IResourceStream getResourceStream() {
              return new BaseStreamResource(documentResource);
          }
      };
  }
  </code></pre>
  
  <p>where <code>BaseStreamResource</code> is the following:</p>
  
  <pre><code>public class BaseStreamResource extends AbstractResourceStream {
      private InputStream      _fileInputStream = null;
      private DocumentResource _resource        = null;
  
      public BaseStreamResource(final DocumentResource documentResource) {
          _resource = documentResource;
      }
  
      @Override
      public InputStream getInputStream() throws ResourceStreamNotFoundException {
          if (_fileInputStream == null) {
              try {
                  if (_resource == null) {
                      throw new ResourceStreamNotFoundException("Resource was null");
                  }
                  _fileInputStream = _resource.getFileInputStream();
              } catch (final ResourceNotAvailableException ex) {
                  throw new ResourceStreamNotFoundException(ex);
              }
          }
          return _fileInputStream;
      }
  </code></pre>
  
  <p>In HTML:</p>
  
  <pre><code>&lt;a wicket:id="linkToPreview" href="#"&gt;
  &lt;img wicket:id="imageThumbnail" alt="Attachment"&gt;&lt;/img&gt;&lt;/a&gt;
  </code></pre>