Databinding JTextfield to int attribute ?

22 views
Skip to first unread message

Axan

unread,
Nov 21, 2011, 6:59:24 AM11/21/11
to JavaBuilders
Hello, I'm new to JavaBuilders and I wonder what's the good way to do
this:
I added an integer attribute "age" on Person, validator restrict the
textfield.text to [0-9]+ regex and I initialized it to a valid value
(instead of default "").
Anyway if the user inputs characters I got format convertion
exceptions.

I understand the framework try to update the integer attribute value
each time the user change the textfield value so it throws exception
if the format is not convertible to integer. But I wonder how to
correctly handle these exceptions ?
I mean in this use case, I don't really care the format conversion
errors untill the "save" button is pressed.

Is there a way to register an exception handler ?
Another idea should be to call custom (user code) setter instead. The
framework could look for a custom setter that would fit before trying
its own conversion. In my case it would look for a "setAge(String)" as
attribute is "age" and binding source is JTextField.text which is a
String.

Well, I can also do with JSpinner, but that's just not fun, and not a
generic solution.

Reply all
Reply to author
Forward
0 new messages