Updating Multiple Views

Discussion in 'Java' started by Jason Cavett, Feb 9, 2007.

  1. Jason Cavett

    Jason Cavett Guest

    Here's my problem...

    I have one Model.
    I can have multiple views to that model (depending on how the user
    wants to see the information).

    Problem: The user can have multiple views to the same model open at
    the same time. If the user changes data in one view (which will
    update the model), I want it to reflect in the other view(s). I
    originally tried this by notifying all observers of the model (which
    includes the original view that was just edited) and repopulating the
    fields of the views. But, when I fire off the notification, I get
    this exception:

    Exception in thread "AWT-EventQueue-0 java.lang.IllegalStateException:
    Attempt to mutate in notification

    ....whenever I edit a TextField or anything else with a
    DocumentListener.

    I sorta understand why this is happening (writeLock() and not being
    able to modify while I'm notifying) but I am very confused on how to
    fix it. Can anybody give any suggestions?
    Jason Cavett, Feb 9, 2007
    #1
    1. Advertising

  2. Jason Cavett

    Daniel Pitts Guest

    On Feb 9, 12:41 pm, "Jason Cavett" <> wrote:
    > Here's my problem...
    >
    > I have one Model.
    > I can have multiple views to that model (depending on how the user
    > wants to see the information).
    >
    > Problem: The user can have multiple views to the same model open at
    > the same time. If the user changes data in one view (which will
    > update the model), I want it to reflect in the other view(s). I
    > originally tried this by notifying all observers of the model (which
    > includes the original view that was just edited) and repopulating the
    > fields of the views. But, when I fire off the notification, I get
    > this exception:
    >
    > Exception in thread "AWT-EventQueue-0 java.lang.IllegalStateException:
    > Attempt to mutate in notification
    >
    > ...whenever I edit a TextField or anything else with a
    > DocumentListener.
    >
    > I sorta understand why this is happening (writeLock() and not being
    > able to modify while I'm notifying) but I am very confused on how to
    > fix it. Can anybody give any suggestions?


    First, this is more on-topic at comp.lang.java.gui.
    Second, your views shouldn't modify any part of the model based while
    responding to a change in the model.

    If you should implement a single model that represents all
    interconnected aspects of your business domain, and have all of your
    components able to read values from the model.

    Having a model observer modify the model runs the risk of infinit
    recursion or infinit loops.
    Daniel Pitts, Feb 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Rogers

    Having One Page Produce Multiple Views

    Tim Rogers, Nov 7, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    547
    George Ter-Saakov
    Nov 10, 2003
  2. Ruben
    Replies:
    3
    Views:
    567
    Dave Mandelin
    Mar 27, 2006
  3. Bill Sexton
    Replies:
    1
    Views:
    405
    Bill Sexton
    Jan 26, 2007
  4. edfialk
    Replies:
    0
    Views:
    273
    edfialk
    May 9, 2008
  5. Jason Cavett

    Multiple Views to a Model

    Jason Cavett, Dec 11, 2008, in forum: Java
    Replies:
    8
    Views:
    865
    Stefan Ram
    Dec 12, 2008
Loading...

Share This Page