Hi,

The "problem" you face is that Wicket tries to find both getter and setter
[1] and if any of them do not exist then it falls back to the field.

I'd continue using a custom IModel for this use case.

And I'd also change the type of the "amount" to BigDecimal! Doing math with
doubles when dealing with money is a bomb with a timer!


1.
https://github.com/apache/wicket/blob/51d9e533dc3a45183210a1f4852851b485f02ea3/wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java#L274

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Dec 1, 2017 at 7:54 PM, sorinev <sori...@gmail.com> wrote:

> Wicket 7.9.0.
>
> I have a Java double that is linked to a Wicket Label. This double
> represents a dollar amount, so I want to work with it as a double for math
> purposes. When I display it on the page however, I want it to a be a
> currency formatted String.
>
> I figured I would just add a getter to my page for that property, with a
> return type of String (and do the appropriate actions there). So for a
> member variable called 'amount' of type Double, I have a getter as 'private
> String getAmount()'. It's not working though, it still gets the value
> directly from the property itself when displaying on the page (and seems to
> get displayed as an int, at that).
>
> I was using CompoundPropertyModel at first, then after something i read on
> StackOverflow
> <https://stackoverflow.com/questions/548354/wicket-
> propertymodel-strangeness>
> , I changed it to a PropertyModel, but it's still not working. Does the
> return type of the getter have to match the type of the variable, even if
> the getter method has the appropriate name otherwise? I am currently going
> with the method shown in the second answer by Andreas on that StackOverflow
> question, but I'd rather it be done automatically through PropertyModel or
> CompoundPropertyModel because it looks a lot cleaner.
>
> --
> Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-
> f1842947.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to