首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在页面上找不到Wicket图像组件

在页面上找不到Wicket图像组件
EN

Stack Overflow用户
提问于 2011-04-19 09:24:43
回答 2查看 2.5K关注 0票数 1

当我试图显示一个项目列表时,我会遇到以下问题。对于每个项目,我必须显示一个通过Wicket WebResource动态加载的图像。这些项目一步一步地加载,每次用户滚动,使用Ajax滚动。

错误2011-04-19 09:58:18,000 btpool0 0-1 org.apache.wicket.RequestCycle.logRuntimeException (host=,request=,site=):org.apache.wicket.WicketRuntimeException:在页面com.webapp.document.pages.DocumentListPageid上找不到的组件

=1侦听器接口= RequestListenerInterface name=IResourceListener,method=public抽象空org.apache.wicket.IResourceListener.onResourceRequested()

org.apache.wicket.protocol.http.request.InvalidUrlException: org.apache.wicket.WicketRuntimeException:在页面com.webapp.document.pages.DocumentListPageid =1侦听器接口= RequestListenerInterface name=IResourceListener中找不到组件com.webapp.document.pages.DocumentListPageid,抽象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:在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()

如何解决这个问题呢?

下面是代码中负责添加图像的部分:

代码语言:javascript
复制
previewLink.add(createThumbnailSmall("imageThumbnail", documentModel));

在……里面

代码语言:javascript
复制
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如下:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
<a wicket:id="linkToPreview" href="#">
<img wicket:id="imageThumbnail" alt="Attachment"></img></a>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-28 08:30:01

以下解决方案解决了这个问题:

  • 扩展WebResource类
  • 将扩展类添加到应用程序共享资源

例如:

代码语言:javascript
复制
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添加到共享资源中:

代码语言:javascript
复制
public void init() {
    ... 
    new MyWebResource().addResource();        
    ...
}
票数 1
EN

Stack Overflow用户

发布于 2011-04-19 11:28:20

添加的代码并没有真正为我添加任何线索,但也许我可以帮助缩小它的范围。

堆栈跟踪包含对com.webapp.document.pages.DocumentListPage的引用,该引用可能会调用您发布的一些代码。错误表示错误的url,所以调试到该类中,添加调试打印,并查看包含url的任何字段的值都是值得的。

它甚至可能有助于修改DocumentListPage中的代码(可能暂时用于调试),以便在异常被捕获时捕获org.apache.wicket.protocol.http.request.InvalidUrlException并添加调试打印。

这不是一个真正的答案,但它太大,不能发表评论,也许它会帮助你接近一个答案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5714229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档