Hi all
I am using BeansBinding from java.net and i have a problem. When i sync String property from my model with the (Text) property of some (jTextField) the validator does not run when i do .bind for the first time only (my validator is to check if the jtextField is not null). While sync Float proerty from my model with the (Text) property of other (jTextField) the validator work very will. Did i misunderstod or what is the problem.
GUI code view plaincopy to clipboardprint?
- BeanProperty textProperty = BeanProperty.create("text");
-
- BeanProperty bpDefalutPrice = BeanProperty.create("defaultPrice");
- binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
- currencyPM,bpDefalutPrice,txtPrice,textProperty);
- binding.setConverter(new FloatConverter());
- binding.setValidator(new FloatValidator());
- bindingGroup.addBinding(binding);
-
- BeanProperty bpName = BeanProperty.create("name");
-
- ELProperty testName = ELProperty.create("${name}");
- binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
- currencyPM,testName,txtName,textProperty);
-
- binding.setValidator(new StringNotNullValidator());
- binding.setConverter(new StringConverter());
-
- bindingGroup.addBinding(binding);
- bindingGroup.addBindingListener(this);
- bindingGroup.bind();
-
BeanProperty textProperty = BeanProperty.create("text"); BeanProperty bpDefalutPrice = BeanProperty.create("defaultPrice"); binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, currencyPM,bpDefalutPrice,txtPrice,textProperty); binding.setConverter(new FloatConverter()); binding.setValidator(new FloatValidator()); bindingGroup.addBinding(binding); BeanProperty bpName = BeanProperty.create("name"); ELProperty testName = ELProperty.create("${name}"); binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, currencyPM,testName,txtName,textProperty); binding.setValidator(new StringNotNullValidator()); binding.setConverter(new StringConverter()); bindingGroup.addBinding(binding); bindingGroup.addBindingListener(this); bindingGroup.bind();
String Validator
view plaincopy to clipboardprint?
-
- package view.helper.validator;
-
- import org.jdesktop.beansbinding.Validator;
-
- /**
-
*
- @author mrefaii
- */
- public class StringNotNullValidator extends Validator{
- public Validator.Result validate(String arg) {
- System.out.println("in validator String : " + arg);
- if(arg.trim().equalsIgnoreCase("")){
- return new Result(null, "1X1");
- }
- return null;
- }
-
- }
package view.helper.validator; import org.jdesktop.beansbinding.Validator; /** * * @author mrefaii */ public class StringNotNullValidator extends Validator{ public Validator.Result validate(String arg) { System.out.println("in validator String : " + arg); if(arg.trim().equalsIgnoreCase("")){ return new Result(null, "1X1"); } return null; } }
String converter
view plaincopy to clipboardprint?
-
- package view.helper.converter;
-
- import org.jdesktop.beansbinding.Converter;
-
- /**
-
*
- @author mrefaii
- */
- public class StringConverter extends Converter{
-
- public String convertForward(String arg){
- System.out.println("in string converter forward");
- return arg;
- }
-
- public String convertReverse(String arg){
- System.out.println("in String converter reverse");
- return arg;
- }
-
- }
package view.helper.converter; import org.jdesktop.beansbinding.Converter; /** * * @author mrefaii */ public class StringConverter extends Converter{ public String convertForward(String arg){ System.out.println("in string converter forward"); return arg; } public String convertReverse(String arg){ System.out.println("in String converter reverse"); return arg; } }
Float validator
view plaincopy to clipboardprint?
-
- package view.helper.validator;
-
- import org.jdesktop.beansbinding.Validator;
- /**
-
*
- @author mrefaii
- */
- public class FloatValidator extends Validator{
- public Validator.Result validate(Float arg) {
- System.out.println("in validator Float : " + arg);
- if(arg <=0){
- return new Result(null, "1X3");
- }
- return null;
- }
-
- }
package view.helper.validator; import org.jdesktop.beansbinding.Validator; /** * * @author mrefaii */ public class FloatValidator extends Validator{ public Validator.Result validate(Float arg) { System.out.println("in validator Float : " + arg); if(arg <=0){ return new Result(null, "1X3"); } return null; } }
Float Converter
view plaincopy to clipboardprint?
-
- package view.helper.converter;
-
- import org.jdesktop.beansbinding.Converter;
-
- public class FloatConverter extends Converter{
-
- public String convertForward(Float arg){
- return String.valueOf(arg);
- }
-
- public Float convertReverse(String arg){
- float value;
- try {
- value = (arg == null) ? 0 : Float.parseFloat(arg);
- } catch (NumberFormatException ex) {
- System.out.println("in vali");
- value = 0;
- }
- return value;
-
- }
- }
package view.helper.converter; import org.jdesktop.beansbinding.Converter; public class FloatConverter extends Converter{ public String convertForward(Float arg){ return String.valueOf(arg); } public Float convertReverse(String arg){ float value; try { value = (arg == null) ? 0 : Float.parseFloat(arg); } catch (NumberFormatException ex) { System.out.println("in vali"); value = 0; } return value; } }
please if anyone can help. Very thanks.