質問

I have a checkbox that should be checked if some BigDecimal value is greater that zero. I tried this:

<input title="$i18n.tr('foo')" type="checkbox" name="foo.bar" id="foobar"
#if($foo.bar && $foo.bar.doubleValue() > 0)checked#end/>

(foo is a POJO and bar is BigDecimal field)

But no matter what stores in bar, checkbox is always unchecked. I tried to add onclick event in order to debug it:

onclick="alert('$foo.bar.doubleValue()');"

And here I can see that bar's value is OK, e.g. 15.0, so it's not a value's problem.

How to compare BigDecimal with another number in Velocity's template?

役に立ちましたか?

解決

Seems like there's no simple and elegant solution for this problem, so I just moved verification into Java code and use it's result in template as boolean variable:

#if($isBar)checked#end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top