In my web app, during some change over the object, i need to send a mail about the changes happened in the object.
My question is how to write a listener for this.
Please give me some article regarding this.
Thanks
In my web app, during some change over the object, i need to send
Share
A typical implementation could be like this: your object is observable. So every time, one of the (observed) values changes, an event is fired and all registered listeners are notified. One of those listeners now would be designed to take the notification and create and send an EMail (Java Mail API)
Let’s take a sample bean which we make observable:
The Listener interface:
The Observable interface:
And the EMailer:
EDIT
Corrected an ugly mistake in the setter method – now the event is fired after the property has been set. Was the other way round, with the side effect, that if a listener read the changed property, he still saw the old, unchanged value…