Tapestry 5.0.5 bug, TAPESTRY-1648

本文介绍了一个Tapestry框架中处理BigDecimal类型时遇到的NullPointerException问题及其解决方案。通过自定义BigDecimalTranslator并调整Tapestry-ioc源码,成功解决了表单提交时的异常。
有一个domian object, 其中有个property的type是BigDecimal。在增加bigdecimal的translator后。

[code]
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();
}

}[/code]

然后contribute 到AppModule

[code] 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());
}[/code]


当提交form时,会发生一个NPE。 错误发生在。org.apache.tapestry.ioc.services.TapestryIOCModule
[code]
// 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);
}
});[/code]

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

[quote]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[/quote]

我试着想去覆盖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上拉下来。 简单的修改为

[code] // 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);
}
});[/code]

打包替换掉tapestry-ioc 5.0.5。 再跑便程序。 ok 通过。 :idea:
为了查找与测绘遥感相关的SCI期刊列表,可以通过学术搜索引擎或访问特定的数据库来获得最新的信息。通常这些资源会定期更新以反映最新收录情况。 些常用的搜索方式包括: 查阅Web of Science (WOS) 数据库 这是最直接的方法之,因为Science Citation Index(SCI)正是由该数据库维护。可以在其中设置关键词为"remote sensing", "surveying and mapping" 或者更具体的主题术语,并选择仅显示被SCI索引的文章和期刊。 利用Google Scholar 虽然不是专门针对SCI期刊,但可以找到很多高影响力的测绘遥感类文章及其发表刊物的信息。从这里也可以了解到哪些是活跃且受认可的研究领域内的出版物。 参考Journal Citation Reports (JCR) 这是个评估科学和技术期刊影响力的重要工具。通过查看影响因子和其他指标,可以帮助确定哪些测绘遥感领域的期刊最具权威性并且属于SCI范畴。 咨询图书馆员或专业人士 大学或研究机构的专业人员能够提供指导和支持,帮助定位最适合需求的具体期刊名称及详情。 订阅行业通讯和服务 某些服务如Elsevier's Scopus也会报告关于各个学科顶级期刊的消息,保持关注可以获得及时的通知。 以下是几个知名的测绘遥感相关SCI期刊的例子: - Remote Sensing of Environment - IEEE Transactions on Geoscience and Remote Sensing - ISPRS Journal of Photogrammetry and Remote Sensing - International Journal of Applied Earth Observation and Geoinformation 请注意,实际的SCI期刊名单可能会随着时间而变化,因此建议总是使用最新的在线资源来进行确认。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值