java - Beans Binding in JTextField doesn't work -


i tried work beans binding in java. followed code in sites. , tried make work.

here, did is, tried update person's first name value entered in textfield user during run time. when click button, contains "omg". if replace "" contains value. refer looks work once. what's wrong it? did miss here? can resolve this?

i interchanged source , target , tried also

import java.beans.propertychangelistener;     import java.beans.propertychangesupport;      public abstract class abstractmodelobject {         private final propertychangesupport propertychangesupport = new propertychangesupport(this);          public void addpropertychangelistener(propertychangelistener listener) {             propertychangesupport.addpropertychangelistener(listener);         }          public void addpropertychangelistener(string propertyname,                 propertychangelistener listener) {             propertychangesupport.addpropertychangelistener(propertyname, listener);         }          public void removepropertychangelistener(propertychangelistener listener) {             propertychangesupport.removepropertychangelistener(listener);         }          public void removepropertychangelistener(string propertyname,                 propertychangelistener listener) {             propertychangesupport.removepropertychangelistener(propertyname,                     listener);         }          protected void firepropertychange(string propertyname, object oldvalue,                 object newvalue) {             propertychangesupport.firepropertychange(propertyname, oldvalue,                     newvalue);         }     }      import java.beans.propertychangelistener;         import java.beans.propertychangesupport;          public class personimpl extends abstractmodelobject implements person{             private string firstname;              private string lastname;               public personimpl()             {              }              public personimpl(string firstname)             {                 this.firstname = firstname;             }              public string getfirstname()             {                  system.out.println("getfirstname");                 return firstname;             }              public void setfirstname(string firstname)              {                  system.out.println("setfirstname");                 string old = this.firstname;                 this.firstname = firstname;                  firepropertychange("firstname",old,firstname);             }          }           public interface person {              void setfirstname(string string);              string getfirstname();          }              public class myframe extends jframe {                 jtextfield field = new jtextfield("omg");                 jbutton button = new jbutton("save");                 person p = new personimpl();                  myframe()                 {                      button.addactionlistener(new actionlistener(){                         @override                         public void actionperformed(actionevent e) {                             system.out.println("first name : " + p.getfirstname());                         }                     });                 }                 private void initdatabinding() {                     if(beans.isdesigntime()){return;}                     beanproperty<person, string> fnameproperty =                              beanproperty.create("firstname");                       beanproperty<jtextfield, string> textproperty =                             beanproperty.create("text");                      bindinggroup bindinggroup = new bindinggroup();    autobinding<jtextfield, string, person, string> firstnamebinding                     = bindings.createautobinding(updatestrategy.read, field, textproperty,p, fnameproperty);                     firstnamebinding.bind();                 }             } 

normally, sort of binding created readwrite. doesn't seem root of issue, consider changing.

the first thing check here put breakpoint on binding create call , make sure it's getting called.

if is, consider adding binding listener before call .bind() , see if reports failed binding operations. should track down problem pretty quickly.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo