views:

237

answers:

0

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?

  1. BeanProperty textProperty = BeanProperty.create("text");
  2. BeanProperty bpDefalutPrice = BeanProperty.create("defaultPrice");
  3. binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
  4. currencyPM,bpDefalutPrice,txtPrice,textProperty);
  5. binding.setConverter(new FloatConverter());
  6. binding.setValidator(new FloatValidator());
  7. bindingGroup.addBinding(binding);
      1. BeanProperty bpName = BeanProperty.create("name");
      1. ELProperty testName = ELProperty.create("${name}");
    1. binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
    2. currencyPM,testName,txtName,textProperty);
    3. binding.setValidator(new StringNotNullValidator());
    4. binding.setConverter(new StringConverter());
      1. bindingGroup.addBinding(binding);
    5. bindingGroup.addBindingListener(this);
    6. 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?

    1. package view.helper.validator;
    1. import org.jdesktop.beansbinding.Validator;
    1. /**
    • *
    • @author mrefaii
  1. */
    1. public class StringNotNullValidator extends Validator{
    2. public Validator.Result validate(String arg) {
    3. System.out.println("in validator String : " + arg);
    4. if(arg.trim().equalsIgnoreCase("")){
    5. return new Result(null, "1X1");
    6. }
    7. return null;
    8. }
    9. }

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?

  1. package view.helper.converter;
    1. import org.jdesktop.beansbinding.Converter;
    1. /**
    • *
    • @author mrefaii
    • */
    • public class StringConverter extends Converter{
      1. public String convertForward(String arg){
    • System.out.println("in string converter forward");
    • return arg;
    • }
      1. public String convertReverse(String arg){
    • System.out.println("in String converter reverse");
    • return arg;
    • }
      1. }

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?

  1. package view.helper.validator;
  2. import org.jdesktop.beansbinding.Validator;
  3. /**
    • *
    • @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?

    1. package view.helper.converter;
    1. import org.jdesktop.beansbinding.Converter;
    1. public class FloatConverter extends Converter{
  1. public String convertForward(Float arg){
    1. return String.valueOf(arg);
    2. }
      1. public Float convertReverse(String arg){
    3. float value;
    4. try {
    5. value = (arg == null) ? 0 : Float.parseFloat(arg);
    6. } catch (NumberFormatException ex) {
    7. System.out.println("in vali");
    8. value = 0;
    9. }
    10. return value;
      1. }
    11. }

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.