在页面上找不到检票口图像组件 [英] Wicket image component not found on page

查看:19
本文介绍了在页面上找不到检票口图像组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试显示项目列表时遇到以下问题.对于每个项目,我必须显示通过 Wicket WebResource 动态加载的图像.这些项目是在用户滚动时使用 Ajax 滚动逐步加载的——一次 50 个.

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 WebResource. The items are loaded step by step — 50 at a time — upon user scrolling, using an Ajax scroll.

[错误] 2011-04-19 09:58:18,000 btpool0-1 org.apache.wicket.RequestCycle.logRuntimeException (host=, request=, site=):org.apache.wicket.WicketRuntimeException: 组件 documentList:scroller:batchElem:666:content:item:3:batchItemContent:linkToPreview:imageThumbnail 在页面 com.webapp.document.pages.DocumentListPage[id = 1] 上找不到listener interface = [RequestListenerInterface name=IResourceListener, method=public abstract void org.apache.wicket.IResourceListener.onResourceRequested()]

[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()]

org.apache.wicket.protocol.http.request.InvalidUrlException: org.apache.wicket.WicketRuntimeException: 组件 documentList:scroller:batchElem:666:content:item:3:batchItemContent:linkToPreview:imageThumbnail在 com.webapp.document.pages.DocumentListPage[id = 1] 侦听器接口 = [RequestListenerInterface name=IResourceListener, method=public abstract void org.apache.wicket.IResourceListener.onResourceRequested()] 上找不到在 org.apache.wicket.protocol.http.WebRequestCycleProcessor.resolve(WebRequestCycleProcessor.java:262)在 org.apache.wicket.RequestCycle.step(RequestCycle.java:1310)在 org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)在 org.apache.wicket.RequestCycle.request(RequestCycle.java:545)在 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)在 org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.CGLIB$doGet$6()在 org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816$$FastClassByGuice$$6d42bf5d.invoke()在 com.google.inject.internal.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)在 com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)在 com.freiheit.monitoring.PerformanceMonitoringMethodInterceptor.invoke(PerformanceMonitoringMethodInterceptor.java:115)在 com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)在 com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:44)在 org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.doGet()在 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)在 org.apache.wicket.protocol.http.WicketFilter$$EnhancerByGuice$$51619816.CGLIB$doFilter$4()

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()

如何解决这个问题?

这是负责添加图像的代码部分:

Here is the part of the code responsible for adding the image:

previewLink.add(createThumbnailSmall("imageThumbnail", documentModel));

createThumbnailSmall(final String id, final IModel<BaseDocument> 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);
        }
    };
}

其中 BaseStreamResource 如下:

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;
    }

在 HTML 中:

<a wicket:id="linkToPreview" href="#">
<img wicket:id="imageThumbnail" alt="Attachment"></img></a>

推荐答案

以下解决方案解决了问题:
- 扩展 WebResource 类
- 将扩展类作为资源添加到应用程序共享资源中

The following solution solved the problem:
- extend WebResource class
- add extended class as a resource to application shared resources

例如:

public class MyWebResource extends WebResource {
    final ValueMap map = new ValueMap();

    @Override
    public IResourceStream getResourceStream() {        
        String fileName = getFileName();
        File file = new File(basePath, fileName);

        if (!file.exists()) {
            LOG.error("File does not exist: " + file);
            throw new IllegalStateException("File does not exist: " + file);
        }       
        return new FileResourceStream(file);
    }           

    public final void addResource() {
        Application.get().getSharedResources().add(getClass().getName(), this);
    }

    protected String getFileName() {
        return getParameters().getString("id");
    }   

    public final String urlFor(final String fileName) {         
        final ResourceReference resourceReference = new ResourceReference(getClass().getName());        
        final String encodedValue = WicketURLEncoder.QUERY_INSTANCE.encode(fileName);
        map.add("id", encodedValue);
        final CharSequence result = RequestCycle.get().urlFor(resourceReference, map);       
        if (result == null) {
            throw new IllegalStateException("The resource was not added! "
                + "In your Application class add the following line:"
                + "MyConcreteResource.INSTANCE.addResource()");
        }   

        String absoluteUrl = RequestUtils.toAbsolutePath(result.toString());        
        return absoluteUrl;     
    } 
}

在Application类的init()中,我已经将MyWebResource添加到共享资源中:

In Application class, in init(), I have added MyWebResource to shared resources:

public void init() {
    ... 
    new MyWebResource().addResource();        
    ...
}

这篇关于在页面上找不到检票口图像组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆