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

Tapestry 显示图片

阅读更多
导入的blog格式乱了,请看我的msn spaces blog:http://dengyin2000.spaces.live.com/blog/cns!AF4AB52B167D7EE7!166.entry
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"> </set-object> </construct></invoke-factory> <contribution configuration-id="tapestry.services.FactoryServices"> <service name="personImage" object="service:ImageService"></service>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</contribution></service-point>
分享到:
评论
2 楼 dengyin2000 2007-01-26  
http://dengyin2000.spaces.live.com/blog/cns!AF4AB52B167D7EE7!166.entry
1 楼 baggiogamp 2007-01-24  
怎么看啊?给个连接啊!

相关推荐

    Tapestry通用WEB框架

    6. **切换皮肤**:在Tapestry中,可以轻松实现皮肤的切换,这通常涉及到更换CSS样式表和可能的图片资源。开发者可以通过配置文件或程序逻辑来改变应用的外观,满足不同用户需求。 7. **自主分页**:Tapestry提供了...

    Tapestry5使用文档

    7. **本地图片显示组件 Img**:显示本地图片。 8. **字符串自动截取组件 FilterInsert**:自动截断过长的字符串,并插入省略号。 9. **Select 列表选择组件 Select**:提供下拉列表供用户选择。 10. **分页组件 ...

    Tapestry字典

    **6.1 源形页面显示图片** 在页面中展示上传的图片,需要处理图片的存储路径和URL。 **6.2 上传文件** Tapestry提供了文件上传组件,支持单文件或多文件上传,以及上传进度监控。 #### 7. 使用公共层...

    tapestry4.0简易教程

    **6.1 源形页面显示图片** - **概念理解:** 在网页上直接展示图片。 - **具体实践:** 使用`&lt;img&gt;`标签,并为其提供图片的URL。 **6.2 上传文件** - **概念理解:** 实现文件上传功能。 - **具体实践:** 在HTML中...

    Tapestry字典0.1.pdf

    - **实现**: 使用`&lt;img&gt;`标签来显示图片。 - **示例**: `${imagePath}" alt="Image"&gt;` **6.2 上传文件** - **实现**: 使用`&lt;tapestry:fileInput&gt;`标签来实现文件上传功能。 - **示例**: `&lt;tapestry:fileInput id=...

    Tapestry开发指南

    3. **Image组件**:显示图片。 4. **Conditional组件**:根据条件渲染或隐藏内容。 5. **GenericLink组件**:生成链接,可用于页面导航。 6. **ExternalLink组件**:创建指向外部URL的链接。 7. **Form组件**:处理...

    Tapestry用户手册

    - 专门用于显示表单字段旁边的标签,并支持验证错误的展示。 - **6.2 域验证** - 如何为表单字段添加验证规则,确保输入数据的有效性。 - **6.3 扩展ValidationDelegate** - 自定义验证逻辑的方法,可以通过扩展...

    Tapesty4水果店实例

    3. **页面(Page)**:页面是Tapestry4中显示给用户的一组组件,每个页面都有唯一的URL。页面可以包含多个组件,组件之间可以通过事件进行通信。 4. **元数据(Metadata)**:元数据用于描述组件、页面和其他对象的...

    Wicket开发指南-简体版

    - **Tapestry概述**:Tapestry也采用了组件化的方式,但在灵活性和性能方面,Wicket表现更佳。 - **ASP.NET概述**:Wicket借鉴了ASP.NET的部分设计理念,但它是纯Java的解决方案,因此在Java平台上更加原生。 - **...

    wicket文档

    Tapestry是一款基于组件的Web应用框架,与Wicket类似,但也存在一些关键区别。Tapestry更适合于构建高度可定制化的Web界面。 - **1.3.3 ASP.NET概述** ASP.NET是由微软公司开发的一套用于构建Web应用程序的技术...

    精美大气的响应式摄影网站模板5597.zip

    例如,滑动效果可以用于图片轮播,点击放大功能可以用于查看高清细节,而过渡效果则可以在用户滚动页面时平滑地显示内容。 此外,模板可能还包含了JavaScript库,如jQuery,用于实现更复杂的交互功能,如图片预加载...

    Wicket开发指南

    - **动态图片:**Wicket支持动态生成图片,这对于创建动态内容非常有用。 - **数据分页:**Wicket内置了数据分页功能,简化了大数据集的处理。 - **树形控件:**Wicket提供了树形控件,适用于展示层次结构数据。 - *...

    wicket 开发指南

    - **动态图片**: 支持动态生成图片。 - **数据分页**: 提供数据分页功能。 - **树形控件**: 支持树形结构的数据展示。 - **国际化**: 内置国际化支持。 - **单元测试**: 支持单元测试和集成测试。 #### 5. Wicket ...

    Wicket中文开发指南

    - **Tapestry概述**:Tapestry也是基于组件的Web框架,但相较于Wicket,其学习曲线较高,且组件之间的交互较为复杂。 - **ASP.NET概述**:虽然不是Java框架,但作为微软推出的Web开发技术,其提供了丰富的工具支持,...

Global site tag (gtag.js) - Google Analytics