cancel
Showing results for 
Search instead for 
Did you mean: 

Error in WD event handling

Former Member
0 Kudos

Hi,

could someone of you please explain to me what is going wrong in the following scenario.

There are two WD views. Both embed other views that could fire the same event. Both views have an event handler for this event.

Step 1: view 1 is called using plug navigation. The embedded view doesn't raise the event so the event handler in view 1 isn't called. View 1 is left using plug navigation. Everything is fine.

Step 2: view 2 is called later on using plug navigation. The embedded view raises the event. And the event handler of view 1 is called. As view 1 isn't active this leads to the error "Cannot navigate from view View1 because it is not part of the current view assembly".

Why does the event handler of view 1 get called? And why doesn't the event handler of view 2 get called?

If only view 2 is called without view 1 before the event handler of view 2 is called correctly. So the first event handler found in an event handler stack wins when the event is raised? Is this the desired behaviour? Or am I doing something wrong?

And just in case this is important, view 1 and view 2 belong to the same component.

Thanks for your help and best regards,

Robert

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hallo Robert

1. Cannot navigate from view View1 because it is not part of the current view assembly" means
    view is not part of the current "window" or "what-you-see". The cause of this error is
     that neither view1 nor view2 are set as default.

2. But let me try to help: how do you start? is view1 the default view? why do you use events to
    navigate between views? Events are usually thrown by the component controller and caught  

    by views (because of mvc design).

3. Can you please try to give a simple explanation as to what exactly you're trying to do.

4.  Events are processed by the queue and there's no way of telling who will be the first,second etc
    in queue ....When programming please bear this remark in mind.

regards

yuval

Former Member
0 Kudos

Hi Yuval,

I'll try to give you a simplified explanation of our application. In fact it's more complex but the same error occurs in a simple WD application I wrote for testing.

So the test application consists of four views:

  • The default view - just to have a default view. With two buttons for plug navigation to view 1 and view 2.
  • View 1. A simple view that embeds view 3 and has an event handler for the one event which is raised in view 3.
  • View 2. A simple view that embeds view 3 and has an event handler for the one event which is raised in view 3.
  • View 3. A simple view that is embedded in view 1 and view 2. With just one button to raise an event (via component controller method).

How to provoke the error:

In the default view I click on the first button to navigate to view 1. View 1 is called. It embeds view 3 with the button to raise the event. I click on the event button in the embedded view 3. The event is raised. The event handler of view 1 catches the event and does its work (do plug navigation back to the default view).

In the default view I click on the second button to navigate to view 2. View 2 is called. It embeds view 3 with the button to raise the event. I click on the event button in the embedded view 3. The event is raised. But the event handler of view 1 catches the event and tries to do the plug navigation back to the default view. Which causes the error since view 1 is not part of the current view assembly. And I expected the event handler of view 2 to be called as view 2 is part of the current view assembly.

If your 4th point is true than I need to change the application as the plug navigation won't be possible in the event handler methods.

And all this event navigation is necessary to prevent cycles in the component usage. In our application the embedded view is part of another WD component so the embedding component needs a reference to the embedded component. But the embedded component additionally needs a reference to the embedding component which would lead to a cycle in the component usage. And as this is not allowed and causes a build error we needed a chance to remove one of the component usages. Event navigation did the trick. Well, nearly.

Regards,

Robert

Former Member
0 Kudos

Hi Robert

1. In your component controller context add one more attribute "currentView".

2. Before your default view fires plug, it should register the name of the target view in the context.

3. In your component controller create two events; one for view1 one for view2.

4. When view3 raises an event3, the component controller reacts and asks the context
    who is the current view. if "currentView" equals view1, then it raises event1, which
    view1 catches. if "currentView" equal view2, it raises event2.

5. At any rate, please remember that a view catches the event and reacts to it only if

    it currently the default view.

Remarks:

1. Your embedded DC should not have a reference to the embedding DC!!!.

    All you have to do is add view3Interface to your window and put it in a UIViewContainer
    inside view1/view2

2. Why are you using view3 if you have only one button in it? Does it have any special
    logic you must re-use? DC usage should be maintained only if it contains reusable code
    or if the project is so big that you may need to cut it into pieces.

Let me know how you managed.

regards

Yuval

Former Member
0 Kudos

Hi Yuval,

responses to your solution:

1. - 4. Either this way or by raising different events in "view 3". Which seems to be possible in some or all of our scenarios. Not the most beautiful solutions but probably there are no others.

5. At any rate, please remember that a view catches the event and reacts to it only if

    it currently the default view.

Maybe I don't understand this right but when the error occurs the view that catches the event wasn't the default view. Not at design time and also not at runtime. That's even the problem. This view wasn't even part of the view assembly. So obviously a non-default view catches the event.

Responses to your remarks:

  1. That's what I did. But in practice the embedded DC needs a way to navigate to components of the embedding DC. And as this isn't possible with circle DC references I'm using the event navigation.
  2. View 3 with one button only was just a simplified example. In practice it contains much more and also gets reused in other DCs.

Thanks so far,

Robert

Former Member
0 Kudos

Hi Thomas

1. Maybe I don't understand this right but when the error occurs the view that catches
    the event  wasn't the default view. Not at design time and also not at runtime.
     That's even the problem.

     This view wasn't even part of the view assembly. So obviously a
     non-default view catches the  event.  It does catch the event but
     gives you an error  because it is not part of the assembly,
isn't?

2. Again I think you architecture should look somewhat different:

    a. Have two views. each view has a button to allow normal navigation.

    b. insert your view3 (as interface) into view1 or view2

    c. to allow communication between view3 and view1 use the component context
        as mapping tool to transfer data between view3 and view1. You may also
        use events on the component controller: from your view3 call a method on the
        component controller. In this component controller method raise event1.
        View1 subscribes to this event. In your eventHandler you may
        pass any arguments you would like. If you wish to call view2 or defaultView from
        view1, you can use normal outbound navigation.

    d. Same goes for view2. Embed view3 if you'd like. Use either mapping or event
        on the component controller to transfer information to view2.

Try my way. I think it is the best solution. I know because I have used it before.

Take it step by step and report back. We are here to help each other.

regards

yuval

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

please award.

regards

yuval

Former Member
0 Kudos

Of course I do.

Thanks for your help.

Best regards,

Robert

Former Member
0 Kudos

Hi Robert

Danke sehr.

Ich wusste nicht ob Du es vergessen hast, oder etwas mit dem SCN falsch ist.

Auf jedem Fall, ich werde mich darauf freuen, wenn Du dich irgendwann zürückmeldest

und uns alle über deine Lösung mehr erzählst.

mfG

Yuval

Former Member
0 Kudos

I guess view1 in your case might be the default view for the window. If this is the case then you will have to set a context whenever you trigger an action in View2--> This will in turn come to the default view View1 and now within the event handler of view1 based on the context value you need to navigate further to view2.

Regards,

MK

Edited by: Murtuza Kharodawala on Mar 1, 2012 8:33 PM

Former Member
0 Kudos

Unfortunately that doesn't seem to be the solution. None of the views is the default view. And the error also occurs in other test cases. It seems to occur whenever a subsequent view raises an event for which another view that was called before has also registered an event handler. And it doesn't matter if the event handler of the first views was called before or not.

Do you have another idea what could be the problem?

Best regards,

Robert