user414967
user414967

Reputation: 5325

property change lister does not invoke the method propertychangeevent

Below is my code regarding property change. If I use this code, public void propertyChange(PropertyChangeEvent evt) will be called properly.

public void setWeekDate(Date weekDate) {        
   firePropertyChange("weekDate", this.weekDate, this.weekDate = weekDate);     
}

But if I use below code public void propertyChange(PropertyChangeEvent evt) will not be called.

public void setWeekDate(Date weekDate) {
    this.weekDate = weekDate;   
    firePropertyChange("weekDate", this.weekDate, weekDate);
}

could anyone tell me whats wrong with the above code?

Upvotes: 1

Views: 232

Answers (1)

David ten Hove
David ten Hove

Reputation: 2826

In the second instance, you provide the same value twice. I'm guessing firePropertyChange does nothing if the value didn't actually change. Try this:

public void setWeekDate(Date weekDate) {
    Date oldValue = this.weekDate;
    this.weekDate = weekDate;   
    firePropertyChange("weekDate", oldValue, this.weekDate);
}

Upvotes: 2

Related Questions