如何将默认值设置为GWT AutoBean? [英] How to set default value to a GWT AutoBean?
问题描述
$ b Example.class:
public static class示例实现Serializable {
public Example2 example2 = new Example2();
public static BigDecimal calc(BigDecimal dec){
return dec!= null? dec:BigDecimal.ZERO;
}
public static class Example2实现Serializable {
public BigDecimal value1 = BigDecimal.ZERO;
public BigDecimal value2 = BigDecimal.ZERO;
public BigDecimal getSum(){
return calc(value1).add(calc(value2));
$ b AutoBean示例:
public inteface示例{
@PropertyName(example2)
public Example2 getExample2();
BigDecimal calc(BigDecimal dec);
}
我尝试这样做
AutoBean Example2:
public interface Example2 {
@PropertyName( value1)
public BigDecimal getValue1();
@PropertyName(value2)
public BigDecimal getValue2();
BigDecimal getSum();
}
还有 Example2Category 。
但是当我尝试获取value1或value2时,我有一个错误:
TypeError:无法读取null的属性
我认为这是因为没有像它们的Class表示那样的初始化值。我尝试这个解决方案,但似乎没有工作。
那么我如何使用init值来表示我的Example2类中的AutoBean?
看起来这是一个BigDecimal问题。对我来说,我将服务器值更改为Double,现在可以工作。
请参阅 Post 。
I have a Class that i wanted to generate his AutoBean.
Example.class :
public static class Example implements Serializable {
public Example2 example2 = new Example2();
public static BigDecimal calc(BigDecimal dec){
return dec != null ? dec: BigDecimal.ZERO;
}
public static class Example2 implements Serializable {
public BigDecimal value1 = BigDecimal.ZERO;
public BigDecimal value2 = BigDecimal.ZERO;
public BigDecimal getSum(){
return calc(value1).add(calc(value2));
}
}
}
AutoBean Example:
public inteface Example {
@PropertyName("example2")
public Example2 getExample2();
BigDecimal calc(BigDecimal dec);
}
I try to do this
AutoBean Example2 :
public interface Example2 {
@PropertyName("value1")
public BigDecimal getValue1();
@PropertyName("value2")
public BigDecimal getValue2();
BigDecimal getSum();
}
There is also Example2Category where the function is implement.
but when i try to get the value1 or value2 i have an Error :
TypeError: Cannot read property of null
i think this happend because there is no initialized values like into their Class representation. I try this solution but dont seems to work.
So How can I represent the AutoBean from my Example2 Class with init values?
It seems like it is a BigDecimal issues. For me i change the Server Value to Double and it work now.
see this Post.
这篇关于如何将默认值设置为GWT AutoBean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!