- 浏览: 60193 次
- 性别:
- 来自: 四川
最新评论
转自:http://tapestry.apache.org/typecoercer-service.html
Type Coercion
Page:TypeCoercer Service |
Page:Type Coercion |
Type Coercion is the conversion of one type of object to a new object of a different type with similar content. Tapestry frequently must coerce objects from one type to another. A common example is the coercion of a string into an integer or a double.
Although type coercions happen more inside tapestry-core (including coercions ofcomponent parameters), they may also happen inside tapestry-ioc, such as when injecting a value, rather than a service, into a builder method.
Like everything else in Tapestry, type coercions are extensible. At the root is theTypeCoercer service. Its configuration consists of a number of CoercionTuples. Each tuple defines how to coerce from one type to another. The initial set of coercions is focused primarily on coercions between different numeric types:
Default Type Coercions
There are a few special coercions related to null there; Object -->List wraps a lone object as a singleton list, we then neednull -->List to ensure that null stays null (rather than a singleton list whose lone element is anull).
Tapestry can interpolate necessary coercions. For example, say it is necessary to coerce aStringBuffer to anInteger; the TypeCoercer service will chain together a series of coercions:
- Object --> String
- String --> Long
- Long --> Integer
Coercing from null
Coercing from null is special; it is not a spanning search as with the other types. Either there is a specific coercion fromnull to the desired type, or no coercion takes places (and the coerced value isnull).
The only built-in null coercion is from null to boolean (which is always false).
List of Coercions
As of Tapestry versions 5.1 and 5.2, the following coercions are available:
Double --> Float Float --> Double Long --> Boolean Long --> Byte Long --> Double Long --> Integer Long --> Short Number --> Long Object --> Object[] Object --> String Object --> java.util.List Object[] --> java.util.List String --> Boolean String --> Double String --> Long String --> java.io.File String --> java.math.BigDecimal String --> java.math.BigInteger String --> java.text.DateFormat String --> java.util.regex.Pattern String --> org.apache.tapestry5.Renderable String --> org.apache.tapestry5.SelectModel String --> org.apache.tapestry5.corelib.ClientValidation String --> org.apache.tapestry5.corelib.LoopFormState String --> org.apache.tapestry5.corelib.SubmitMode String --> org.apache.tapestry5.corelib.data.BlankOption String --> org.apache.tapestry5.corelib.data.GridPagerPosition String --> org.apache.tapestry5.corelib.data.InsertPosition String --> org.apache.tapestry5.ioc.Resource String --> org.apache.tapestry5.ioc.util.TimeInterval boolean[] --> java.util.List byte[] --> java.util.List char[] --> java.util.List double[] --> java.util.List float[] --> java.util.List int[] --> java.util.List java.math.BigDecimal --> Double java.util.Collection --> Boolean java.util.Collection --> Object[] java.util.Collection --> org.apache.tapestry5.grid.GridDataSource java.util.Date --> java.util.Calendar java.util.List --> org.apache.tapestry5.SelectModel java.util.Map --> org.apache.tapestry5.SelectModel long[] --> java.util.List null --> Boolean null --> org.apache.tapestry5.grid.GridDataSource org.apache.tapestry5.ComponentResources --> org.apache.tapestry5.PropertyOverrides org.apache.tapestry5.PrimaryKeyEncoder --> org.apache.tapestry5.ValueEncoder org.apache.tapestry5.Renderable --> org.apache.tapestry5.Block org.apache.tapestry5.Renderable --> org.apache.tapestry5.runtime.RenderCommand org.apache.tapestry5.ioc.util.TimeInterval --> Long org.apache.tapestry5.runtime.ComponentResourcesAware --> org.apache.tapestry5.ComponentResources short[] --> java.util.List
Contributing New Coercions
TypeCoercer is extensible; you may add new coercions as desired. For example, let's say you have aMoney type that represents an amount of some currency, and you want to be able to convert fromBigDecimal toMoney. Further, let's assume that Money has a constructor that accepts aBigDecimal as its parameter. We'll use a little Tapestry IOC configuration jujitsu to inform the TypeCoercer about this coercion.
public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) { Coercion<BigDecimal, Money> coercion = new Coercion<BigDecimal, Money>() { public Money coerce(BigDecimal input) { return new Money(input); } }; configuration.add(new CoercionTuple<BigDecimal, Money>(BigDecimal.class, Money.class, coercion)); }
Further, since TypeCoercer knows how to convert Double to BigDecimal, or evenInteger (toLong to Double) to BigDecimal, all of those coercions would work as well.
When creating a coercion from null, use Void.class as the source type. For example, the built-in coercion fromnull toBoolean is implemented as:
configuration.add(new CoercionTuple(void.class, Boolean.class, new Coercion<Void, Boolean>() { public Boolean coerce(Void input) { return false; } }));
发表评论
-
struts2 中获取 web资源的方式
2016-01-08 17:02 475在struts2中获取 web资源的方式大致可分为获取扩展 ... -
sql server、db2、oracle 存储过程动态sql语句示例
2015-01-31 19:00 1793Oracle CREATE OR REPLACE PRO ... -
ie9 中出现不明的异常(参数是必选项 (Argument not optional)、尚未实现)等
2015-01-27 23:57 1271<script type="text/jav ... -
SAXParseException: The content of element type "configuration" must match
2014-09-15 23:57 1926在mybatis的配置文件中新增加<databaseI ... -
java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR
2014-09-15 23:45 1932在mybatis 中使用databaseIdProvide ... -
spring mvc3 + fastjson 转换 REST 参数以及输出
2014-03-27 00:16 4194spring 3可以支持Rest风格参数,其内置了jack ... -
eclipse中编辑log4j 的xml配置文件时,自动提示
2014-03-27 00:05 843方法1. 配置log4j.dtd文件: Windows - ... -
java json 转换之 Jackson 框架
2013-08-01 21:50 1114转自:http://www.cnblogs.com/hooj ... -
eclipse/myeclise 自定义注释中的变量名称
2013-07-01 23:18 939eclipse/myeclipse中自带了 ... -
Eclipse Class Decompiler——Java反编译插件
2012-11-08 22:41 1206Eclipse Class Decompiler,整 ... -
struts+spring+hibernate整合问题解决方法 陆续更新中....
2009-01-01 10:33 845在整合ssh过程中出现的问题和解决方法: 一、 严重: Ser ... -
DWR通过Annotation与spring整合
2009-01-21 22:05 636DWR 2.0 增加了一个很有趣的新特性,Annotat ... -
div嵌套页面 div加载页面 (其中获取目标页面的内容是用dwr框架连接java程序做的)
2009-03-15 16:58 630前段时间因为有需要,要在div中加载一个页面。但是以前没做过, ... -
tapestry autocomplete 更改样式及定位
2009-07-09 19:02 682版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文 ... -
Java中的main()方法详解
2009-07-12 16:23 611源文作者:leizhimin 源文链接:http:/ ... -
tapestry5 集成 spring 的事务管理
2009-07-22 15:43 558说明:使用的是tapestry5.1.0.5 和spring ... -
tapestry5 布局 参数的处理
2009-07-23 17:24 378<?xml version="1.0" ... -
tapestry不支持 等html特殊符号的解决方法
2009-07-23 17:34 481在使用tapestry时,偶然发现使用 &a ... -
WebService大讲堂之Axis2(1):用POJO实现0配置的WebService
2009-07-28 15:01 402转自:http://space.itpub.net ... -
WebService大讲堂之Axis2(2):复合类型数据的传递
2009-07-28 15:25 472转自:http://space.itpub.net/12921 ...
相关推荐
一个web框架的IOC实现,Apache tapestry-ioc
tapestry-bin-5.1.0.5
自定义的邮件组件!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
android-priority-jobqueue.zip,一种专为android编写的作业队列,用于方便地调度在后台运行的作业(任务),提高用户体验和应用程序稳定性。一种专为android编写的作业队列,用于方便地调度在后台运行的作业(任务)...
Tapestry5最新中文教程.doc 作者 Renat Zubairov & Igor Drobiazko译者 沙晓兰 发布于 2008年7月2日 下午9时30分 社区 Java 主题 Web框架 ----------------------------------------- Tapestry5.1实例教程.pdf ...
tapestry5最新的书籍。pdf格式。原版。购买要几十刀呢!
tapestry-project-4.1.5 裏面有例子和所用到的包
(Tapestry)An infrastructure for Fault-Tolerant Wide-area Location and Routing.
您可以看到以下日志1: : -> org.apache.tapestry:quickstart(Tapestry 5 快速入门项目) 2: -> org.apache.tapestry:tapestry-archetype (Tapestry 4.1.6 Archetype) 所以你想创建 Tapestry 5 quickStart 项目...
Tapestry5和jQuery集成.使用jQuery以极少的兼容问题完全替换Prototype 和 Scriptaculous库 标签:tapestry5
apache-tapestry-5.3.8-bin.zip
mandala-the-wall-tapestry-cave.com- 挂毯专家Mandala壁挂毯洞穴可帮助您将墙壁装饰变成真正的壁画,因此快来探索我们令人难以置信的圆形沙滩巾,壁挂毯和曼陀罗挂毯系列。 请从另一个角度考虑墙面设计,因为墙面...
tapestry5.3.2最新教程--开发模式maven3+tapestry5.3.2+tapestry-hibernate5
tapestry-spring-5.2.6.jar,java spring框架依赖,可以直接使用
包含: tapestry 的源代码, tapestry集成spring2.0 tapestry快速启动 tapestry upload tapestry hibernate tapestry annotations
不必关心链接!不必关心请求(http request)到了哪里!...Tapestry构建于底层的request-resonse模式,基于Servlet技术,抽象出面向组件开发的模型。Tapestry关心的是:页面、组件、事件、对象、方法、属性!
一个关于table在tapestry里应用的例子
这个项目只是看如何使Tapestry与Spring Boot一起使用 笔记 它使用广口瓶包装 它仍然使用src / main / webapp 它不使用web.xml 去做 弄清楚如何将src / main / webapp移到资源上,或者更像是启动所期望的东西 集成...
Tapestry 不必关心链接!不必关心请求(http request)到了哪里!不必关心响应(http response)要转向哪里!Tapestry构建于底层的request-resonse模式,基于Servlet技术,抽象出面向组件开发的模型。Tapestry关心的是:...