Re: Updating Multiple Views - Java
This is a discussion on Re: Updating Multiple Views - Java ; On Feb 9, 12:41 pm, "Jason Cavett" <jason.cav...> 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).
>
...
-
Re: Updating Multiple Views
On Feb 9, 12:41 pm, "Jason Cavett" <jason.cav...> 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.
-
Re: Updating Multiple Views
On Feb 9, 6:23 pm, "Daniel Pitts" <googlegrou...@coloraura.com> wrote:
> On Feb 9, 12:41 pm, "Jason Cavett" <jason.cav...> 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.- Hide quoted text -
>
> - Show quoted text -
> First, this is more on-topic at comp.lang.java.gui.
Okay
> [...]
I think there's some confusion (although, I have figured out a
solution to my problem).
I have a model - and, yes, there's only one. It extends Observable.
I have views - they implement Observer. The user can have multiple
views open to the same model. When the user makes a change to the
view, this triggers the controller which updates the model. The
model, once updated, fires off a notify to its Observers (all the
views) and the views are then updated. I used a flag so that a view
cannot be updated more than once in an "edit" (which prevents any
possibility of infinite loops).
I know MVC can be implemented in a few different ways (and nobody
seems to agree on one). If the way I'm doing it is flat out wrong, it
would be useful to know. (Or if there is a change I should be making,
I'd appreciate knowing that as well.)
Thanks for your help.
-
Re: Updating Multiple Views
On Feb 12, 7:25 am, "Jason Cavett" <jason.cav...> wrote:
> On Feb 9, 6:23 pm, "Daniel Pitts" <googlegrou...@coloraura.com> wrote:
>
>
>
> > On Feb 9, 12:41 pm, "Jason Cavett" <jason.cav...> 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.- Hide quoted text -
>
> > - Show quoted text -
> > First, this is more on-topic at comp.lang.java.gui.
>
> Okay
>
> > [...]
>
> I think there's some confusion (although, I have figured out a
> solution to my problem).
>
> I have a model - and, yes, there's only one. It extends Observable.
> I have views - they implement Observer. The user can have multiple
> views open to the same model. When the user makes a change to the
> view, this triggers the controller which updates the model. The
> model, once updated, fires off a notify to its Observers (all the
> views) and the views are then updated. I used a flag so that a view
> cannot be updated more than once in an "edit" (which prevents any
> possibility of infinite loops).
>
> I know MVC can be implemented in a few different ways (and nobody
> seems to agree on one). If the way I'm doing it is flat out wrong, it
> would be useful to know. (Or if there is a change I should be making,
> I'd appreciate knowing that as well.)
>
> Thanks for your help.
Sounds like a reasonable approach, perhaps giving us an sscce would
help us identify your problem:
<http://physci.org/codes/sscce/>
Similar Threads
-
By Application Development in forum Object
Replies: 4
Last Post: 05-19-2007, 05:21 PM
-
By Application Development in forum Adobe Acrobat
Replies: 0
Last Post: 02-28-2007, 12:30 PM
-
By Application Development in forum Graphics
Replies: 0
Last Post: 02-21-2005, 08:46 AM
-
By Application Development in forum Graphics
Replies: 0
Last Post: 12-21-2004, 02:11 PM
-
By Application Development in forum Mutt
Replies: 3
Last Post: 06-09-2004, 07:04 AM