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

Tapestry 5.0.5 bug, TAPESTRY-1648

阅读更多
有一个domian object, 其中有个property的type是BigDecimal。在增加bigdecimal的translator后。

package com.javaeye.dengyin2000.gtts.tapestry;

import java.math.BigDecimal;

import org.apache.tapestry.Translator;
import org.apache.tapestry.ValidationException;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.internal.util.InternalUtils;

public class BigDecimalTranslator implements Translator<BigDecimal> {

	public BigDecimal parseClient(String clientValue, Messages messages)
			throws ValidationException {
        if (InternalUtils.isBlank(clientValue))
            return null;

        try
        {
            return new BigDecimal(clientValue.trim());
        }
        catch (NumberFormatException ex)
        {
            throw new ValidationException(messages.format("number-format-exception", clientValue));
        }
	}

	public String toClient(BigDecimal value) {
		return value == null ? "" : value.toString();
	}

}


然后contribute 到AppModule

    public static void contributeTranslatorDefaultSource(
            MappedConfiguration<Class, Translator> configuration)
    {
    	configuration.add(BigDecimal.class, new BigDecimalTranslator());
    }
    
    public static void contributeTranslatorSource(
            MappedConfiguration<String, Translator> configuration)
    {
    	configuration.add("bigdecimal",  new BigDecimalTranslator());
    }





当提交form时,会发生一个NPE。 错误发生在。org.apache.tapestry.ioc.services.TapestryIOCModule
        // String to BigDecimal is important, as String->Double->BigDecimal would lose
        // precision.

        add(configuration, String.class, BigDecimal.class, new Coercion<String, BigDecimal>()
        {
            public BigDecimal coerce(String input)
            {
                return new BigDecimal(input);
            }
        });


这里有个很明显的错误。  就是当input为null时。 就发生了NPE.错误如下:

引用
Caused by: org.apache.tapestry.ioc.internal.util.TapestryException: Failure writing parameter value of component basicinformation/AddOrEditDriver:carlong: Coercion of null to type java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal) failed: java.lang.NullPointerException [at classpath:com/javaeye/dengyin2000/gtts/pages/basicinformation/AddOrEditDriver.html, line 50, column 115]
    at org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.writeParameter (InternalComponentResourcesImpl.java:239)
    at org.apache.tapestry.corelib.base.AbstractTextField._$update_parameter_value(AbstractTextField.java)
    at org.apache.tapestry.corelib.base.AbstractTextField.processSubmission (AbstractTextField.java:181)
    at org.apache.tapestry.corelib.base.AbstractField.processSubmission(AbstractField.java:200)
    at org.apache.tapestry.corelib.base.AbstractField.access$100(AbstractField.java:45)
    at org.apache.tapestry.corelib.base.AbstractField$ProcessSubmissionAction.execute(AbstractField.java:114)
    at org.apache.tapestry.corelib.base.AbstractField$ProcessSubmissionAction.execute(AbstractField.java:108)
    at org.apache.tapestry.corelib.components.Form.onAction(Form.java:364)
    ... 45 more
Caused by: java.lang.RuntimeException: Coercion of null to type java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal) failed: java.lang.NullPointerException
    at org.apache.tapestry.ioc.internal.services.TypeCoercerImpl.coerce(TypeCoercerImpl.java:154)
    at $TypeCoercer_1149d2e0ddf.coerce($TypeCoercer_1149d2e0ddf.java)
    at org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.writeParameter(InternalComponentResourcesImpl.java:233)
    ... 52 more
Caused by: java.lang.NullPointerException
    at java.math.BigDecimal .<init>(BigDecimal.java:594)
    at org.apache.tapestry.ioc.services.TapestryIOCModule$7.coerce(TapestryIOCModule.java:219)
    at org.apache.tapestry.ioc.services.TapestryIOCModule$7.coerce(TapestryIOCModule.java :217)
    at org.apache.tapestry.ioc.services.CoercionTuple$CoercionWrapper.coerce(CoercionTuple.java:53)
    at org.apache.tapestry.ioc.internal.services.CompoundCoercion.coerce(CompoundCoercion.java:48)
    at org.apache.tapestry.ioc.internal.services.TypeCoercerImpl.coerce(TypeCoercerImpl.java:150)
    ... 54 more


我试着想去覆盖Tapestry IOC module 的这快代码。  然而没有用。 然后google, 发现原来这是个bug。 这个bug会在5.0.6中解决。可是这是个很明显的错误呀。也不尽快解决掉。 具体可以看。https://issues.apache.org/jira/browse/TAPESTRY-1648, 然后发贴到Tapestry mailling list上问 也没有下文。  既然这样,也只有去自己修改Tapestry-ioc的source code了。 其实这也很简单, 如果是是null 或者是 空字符的话 renturn null就是了。  ok  把tapestry的ioc用svn上拉下来。  简单的修改为

        // String to BigDecimal is important, as String->Double->BigDecimal would lose
        // precision.

        add(configuration, String.class, BigDecimal.class, new Coercion<String, BigDecimal>()
        {
            public BigDecimal coerce(String input)
            {
                    if (input == null || input.trim().length() == 0)
                        return null;
                    return new BigDecimal(input);
            }
        });


打包替换掉tapestry-ioc 5.0.5。 再跑便程序。  ok  通过。
分享到:
评论
1 楼 DigitLiao 2007-09-21  
請教一下,如果我在 AppModule 加入下列方法會有什麼影響嗎?我對 ioc 還不是很熟悉。

我試了一下,這樣子可以正確將 null 轉換為 Integer 或 Long, 否則一遇到 null 就會有發生錯誤。

而這篇文章提到的方法似乎對我無效
http://www.mail-archive.com/users@tapestry.apache.org/msg15168.html

public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
    	System.out.println("contributeTypeCoercer ===============================");
    	
    	CoercionTuple tuple = new CoercionTuple(Object.class, Long.class, new Coercion<Object, Long>()
        {
            public Long coerce(Object input) {
            	if (input == null)	return null;
            	
                try {
                	return new Long(input.toString());
                } catch (Exception e) {
                	return null;
                }
            }
        });
    	
        configuration.add(tuple);
        
        CoercionTuple tupleInt = new CoercionTuple(Object.class, Integer.class, new Coercion<Object, Integer>()
                {
                    public Integer coerce(Object input) {
                    	if (input == null)	return null;
                    	
                        try {
                        	return new Integer(input.toString());
                        } catch (Exception e) {
                        	return null;
                        }
                    }
                });
            	
                configuration.add(tupleInt);
    }
[url]

相关推荐

    tapestry-ioc-5.0.3-src

    一个web框架的IOC实现,Apache tapestry-ioc

    tapestry-bin-5.1.0.5

    tapestry-bin-5.1.0.5

    tapestry-clojure-5.4-beta-3.zip

    android-priority-jobqueue.zip,一种专为android编写的作业队列,用于方便地调度在后台运行的作业(任务),提高用户体验和应用程序稳定性。一种专为android编写的作业队列,用于方便地调度在后台运行的作业(任务)...

    tapestry5 build web application-alexander

    tapestry5最新的书籍。pdf格式。原版。购买要几十刀呢!

    tapestry教程资料文档合集

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

    (Tapestry)An infrastructure for Fault-Tolerant Wide-area Location and Routing.ppt

    (Tapestry)An infrastructure for Fault-Tolerant Wide-area Location and Routing.

    tapestry-project-4.1.5

    tapestry-project-4.1.5 裏面有例子和所用到的包

    tapestry-with-all-funtionlity

    您可以看到以下日志1: : -&gt; org.apache.tapestry:quickstart(Tapestry 5 快速入门项目) 2: -&gt; org.apache.tapestry:tapestry-archetype (Tapestry 4.1.6 Archetype) 所以你想创建 Tapestry 5 quickStart 项目...

    Tapestry - Round Beach Towel-crx插件

    mandala-the-wall-tapestry-cave.com - Tapestry专家,曼陀罗墙壁挂毯的洞穴有助于您将墙壁装饰转变为真正的墙壁艺术,所以来探索我们的圆形海滩毛巾,墙壁挂毯和曼荼罗挂毯的令人难以置信的集合。请考虑从另一...

    tapestry 5.3中文教程

    tapestry5.3.2最新教程--开发模式maven3+tapestry5.3.2+tapestry-hibernate5

    apache-tapestry-5.3.8-bin.zip

    apache-tapestry-5.3.8-bin.zip

    Tapestry5和jQuery集成tapestry5-jquery.zip

    Tapestry5和jQuery集成.使用jQuery以极少的兼容问题完全替换Prototype 和 Scriptaculous库 标签:tapestry5

    Tapestry-and-Spring-Boot:Spring Boot和Apache Tapestry的编写拙劣且混乱的实现

    这个项目只是看如何使Tapestry与Spring Boot一起使用 笔记 它使用广口瓶包装 它仍然使用src / main / webapp 它不使用web.xml 去做 弄清楚如何将src / main / webapp移到资源上,或者更像是启动所期望的东西 集成...

    tapestry-spring-5.2.6.jar

    tapestry-spring-5.2.6.jar,java spring框架依赖,可以直接使用

    tapestry-src-5.1.0.5.zip

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

    tapestry-cdi:挂毯-cdi

    Tapestry-CDI 模块允许注入所有类型的 JSR 299 托管 bean(POJO、EJB、Web 服务等),因为它们由 CDI 容器管理。 该实现是标准的,并且已经针对 、 、 和!特征@Inject CDI bean 为做出贡献,以便我们可以@Inject ...

    Tapestry4.1.2入门-介绍

    Tapestry 不必关心链接!不必关心请求(http request)到了哪里!不必关心响应(http response)要转向哪里!Tapestry构建于底层的request-resonse模式,基于Servlet技术,抽象出面向组件开发的模型。Tapestry关心的是:...

    Tapestry4.1.2 入门-介绍

    不必关心链接!不必关心请求(http request)到了哪里!...Tapestry构建于底层的request-resonse模式,基于Servlet技术,抽象出面向组件开发的模型。Tapestry关心的是:页面、组件、事件、对象、方法、属性!

    Tapestry-3.0.4-bin.zip

    这个是开发tapestry3所用的JAR包

Global site tag (gtag.js) - Google Analytics