Skip to main content

Validating datas

1 reply [Last post]
ramon_lopes
Offline
Joined: 2007-04-20
Points: 0

Hi Folks,

How can I validate some datas with JavaFX? I think I have to triggers, then I tried to implement it as follow:

class Person {
attribute nome: String;
attribute idade: Number;
}

trigger on Person.nome = newValue{
if(newValue<0){
Person.idade = null; //Cannot assigns the value to attribute
println("Value is Invalid!");
}
else{
Person.idade = newValue;
}
}

But this form isn't correct! Can anyone help me?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

You try to assign String attribute to Number
To convert String value to number you can use java DecimalFormat class:
[code]
import java.text.DecimalFormat;

trigger on Person.nome = newValue{
var num = DecimalFormat.getInstance().parse(newValue);
if(num < 0){
idade = null; //Cannot assigns the value to attribute
println("Value is Invalid!");
} else{
idade = num;
}
}

[/code]