Friday, 1 March 2013

Griffon - restricting a textfield to numbers

With my latest Griffon+JavaFX application, I wasn't having any luck binding a textfield to a 'float' property in my model. So to work around it temporarily, I've added a change listener which will veto any input that isn't a number.

This example is basically using a very Java centric approach: Now, we can simplify this by using the Groovy way: See Groovy way to implement interfaces to understand how this is implementing the interface.

If we want to have several text fields using the same logic, we can define the closure in the Controller and reference that in many places: Still, this is not optimal since I have to use Strings instead of Floats in my model - but it does let me continue with whats important right now. Hopefully the binding bug can be fixed soon.

0 comments:

Post a Comment