`
ruruhuang
  • 浏览: 189247 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Tapestry 显示图片

阅读更多
what you&aposre doing is trying to use a @Insert component to insert a blobin your page. It will never work like that since Tapestry will actually tryto display the string representation of your blob (if you callpersonImage.toString() you&aposll get exactly that "oracle.sql.BLOB@1176e8a").You need something a bit more sophisticated. I&aposve done exactly what you&aposretrying to do so I&aposll explain it to you. I won&apost past all my code since it&apossvery application-specific.First you need to create a service that will produce the image contents, socreate a class for that. Something like this:public class ImageService implements IEngineService {   public ILink getLink(boolean isPost, Object parameters) {      Object personId = parameterArray[0];      Map serviceParameters = new HashMap();      serviceParameters.put(ServiceConstants.SERVICE, getName());      serviceParameters.put(ServiceConstants.PARAMETER, new Object[] {personId });      return linkFactory.constructLink(this, isPost, serviceParameters,true);   }    public String getName() {        return "personImage";    }   public void service(IRequestCycle cycle) throws IOException {      // here you have to set the appropriate content type      // I&aposm assuming it&aposs a jpeg image.      ContentType contentType = new ContentType("image/jpeg");      OutputStream outputStream = webResponse.getOutputStream(contentType);      Object[] parameters = linkFactory.extractListenerParameters(cycle);      Integer personId = (Integer) parameters[0];  // you have the ID, so here you do whatever you have to do      // to fetch the person object      Person person = whatever...      // then you have to write the image contents to the output stream.      int length = person.personImage.length();      outputStream.write(person.personImage.getBytes(0,length));      outputStream.close();   }}On the html page you&aposll have to use an img tag with the source being theservice you just created:On the component&aposs java class you&aposll need something like:// This is the hivemind service being injected@InjectObject("service:ImageService")public abstract IEngineService getProductImageService();public String getImageLink() {    Object[] parameters = new Object[1];    // I&aposm assuming there is a "person" variable in page    // with the person object you want to display.    parameters[0] = person.personID;    return getProductImageService().getLink(false,parameters).getAbsoluteURL();    }... next you&aposll also have to tell hivemind about the service in yourhivemodule.xml<service-point id="ImageService" interface="org.apache.tapestry.engine.IEngineService">   <invoke-factory>      <construct class="my.package.ImageService">         <set-object property="linkFactory" value="infrastructure:linkFactory">      </construct>   </invoke-factory></service-point>  <contribution configuration-id="tapestry.services.FactoryServices">   <service name="personImage" object="service:ImageService"></contribution>That&aposs more or less how I did it. I think that&aposs about it, but if I forgotanything I guess the docs can fill in.Denis
分享到:
评论

相关推荐

    tapestry教程资料文档合集

    Tapestry5最新中文教程.doc 作者 Renat Zubairov & Igor Drobiazko译者 沙晓兰 发布于 2008年7月2日 下午9时30分 社区 Java 主题 Web框架 ----------------------------------------- Tapestry5.1实例教程.pdf ...

    深入浅出Tapestry

    资源名称:深入浅出Tapestry内容简介:本书以循序渐进的方式,从Tapestry框架技术的基本概念入手,讲解Tapestry框架在J2EE Web应用程序中的整体架构实现。使读者在学习如何使用Tapestry框架技术的同时,还能够获得在...

    tapestry官方中文文档

    Tapestry 4 官方文档中文版本,现在中文资料比较少,和大家共享一下

    tapestry 实例

    tapestry 实例tapestry 实例tapestry 实例tapestry 实例

    tapestry5以上的帮助事例,帮助文档与spring衔接文档

    Tapestry是一个基于控件的框架以致于用它开发Web应用类似开发传统的GUI应用。你用Tapestry开发Web应用时你无需关注以操作为中心的(Operation-centric) Servlet API.引用Tapestry网站上的一句话:"Tapestry用对象...

    Tapestry5.0.16_API文档

    Tapestry5.0.16文档和大家一起学习

    tapestry3开发指南,带tapestry3所有jar包

    tapestry3开发指南,带tapestry3所有jar包

    Tapestry4开发指南

    Tapestry4开发指南

    深入浅出tapestry

    本书以循序渐进的方式,从Tapestry框架技术的基本概念入手,讲解Tapestry框架在J2EE Web应用程序中的整体架构实现。使读者在学习如何使用Tapestry框架技术的同时,还能够获得在J2EE Web应用程序中应用Tapestry框架的...

    tapestry5.2.6 jar包

    tapestry5.2.6 最新jar包,Tapestry框架是一个位于java servlet容器和Tapestry应用程序之间的层

    tapestry技术

    tapestry技术 Tapestry是一个开源的基于servlet的应用程序框架,它使用组件对象模型来创建动态的,交互的web应用。一个组件就是任意一个带有jwcid属性的html标记。其中jwc的意思是Java Web Component。Tapestry使得...

    tapestry-src-5.1.0.5.zip

    包含: tapestry 的源代码, tapestry集成spring2.0 tapestry快速启动 tapestry upload tapestry hibernate tapestry annotations

    Tapestry开发指南

    Tapestry是一个开源的基于servlet的应用程序框架,它使用组件对象模型来创建动态的,交互的web应用。一个组件就是任意一个带有jwcid属性的html标记。其中jwc的意思是Java Web Component。Tapestry使得java代码与html...

    Tapestry5最新中文入门实例教程

    本文介绍Tapestry框架版本5。本文利用Tapestry 5开发一个简单的具有创建/读/更新/删除功能的应用,在创建这个应用的过程中,本文体会到Tapestry带来的开发效率的提升。从多方面来讲解 Tapestry应用,比如应用的...

    Tapestry通用WEB框架

    Tapestry通用WEB框架支持,切换皮肤,自主分页,

    Tapestry

    Tapestry简明教程

    tapestry学习入门资料

    强大的tapestry框架的学习入门资料,详细介绍了tapestry的常用开发文档。

    Tapestry 5 電子書

    最新Tapestry 5 電子書

    tapestry源码 api等

    tapestry源码文档以及API,需要更早版本请私信

Global site tag (gtag.js) - Google Analytics