Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 901717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:36:01+00:00 2026-05-15T15:36:01+00:00

In my web app, during some change over the object, i need to send

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:36:02+00:00Added an answer on May 15, 2026 at 3:36 pm

    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:

    public class Bean implements Observable{
    
      // code to maintain listeners
      private List<Listener> listeners = new ArrayList<Listener>();
      public void add(Listener listener) {listeners.add(listener);}
      public void remove(Listener listener) {listeners.remove(listener);}
    
      // a sample field
      private int field;
      public int getField() {return field;}
      public int setField(int value) {
        field = value;
        fire("field");        
      }
    
      // notification code
      private void fire(String attribute) {
        for (Listener listener:listeners) {
          fieldChanged(this, attribute);
        }
      }
    }
    

    The Listener interface:

    public interface Listener {
      public void fieldChanged(Object source, String attrbute);
    }
    

    The Observable interface:

    public interface Observable {
      public void add(Listener listener);
      public void remove(Listener listener);
    }
    

    And the EMailer:

    public class Sender implements Listener {
    
      public void register(Observable observable) {observable.add(this);}
      public void unregister(Observable observable) {observable.remove(this);}
    
      public void fieldChanged(Object source, String attribute) {
        sendEmail(source, attribute); // this has to be implemented
      }
    
    }
    

    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…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just created some hosting space for my web app. However, when I change
I have a winforms app, that's locking up during a web service request I've
We are having performance issues on our web app during peak times, which is
I have a web-app consisting of some html forms for maintaining some tables (SQlite,
I am trying to make some enhancements to a production web app. After quite
While analyzing some approaches to making our web app easier to deploy on our
Reviewing a stack trace of a non-responsive web-app, I realized that some of the
For some reason every 3-5 days our web app loses the ability to open
My Java web app running Tomcat (7.0.28) periodically becomes unresponsive. I'm hoping for some
I'm very keen to make use of some build techniques in my Javascript/Web App

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.