Injected bean set to null after transition between views

83 views
Skip to first unread message

Dubnet

unread,
Jan 5, 2013, 12:50:10 PM1/5/13
to swiz-fr...@googlegroups.com
I have a ViewNavigatorApplication which has a view. In that view I have injected a model bean. All is working ok and when navigating to the view, it can see the injected model data.
 
The issue I have is that when I set a Transiton to the navigator.defaultPushTrasition and run the application the view mentioned above no longer sees the model bean and when I debug its set to null.
 
ANy ideas why this is happening please?

Brian Kotek

unread,
Jan 5, 2013, 9:05:46 PM1/5/13
to swiz-fr...@googlegroups.com
If the transition triggers a removedFromStage event, the view will be torn down and the injections cleared out. If that's the case, you'd need the view to implement ITearDownValidator to prevent the automatic tear down of the bean, and then manage tearing down the bean yourself.


--
You received this message because you are subscribed to the Google Groups "Swiz Framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/QnSfO0CJC7UJ.
To post to this group, send email to swiz-fr...@googlegroups.com.
To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swiz-framework?hl=en.

Dubnet

unread,
Jan 6, 2013, 12:23:08 AM1/6/13
to swiz-fr...@googlegroups.com
Thanks for your reply. Could you please put up a small sample of how I might do this. I also get similar issues with some mxml components. Would your solution resolve this also?
 
Thanks again

Dubnet

unread,
Jan 6, 2013, 12:25:02 AM1/6/13
to swiz-fr...@googlegroups.com
Im also using SwizMobile.swc and org.swizframework.core.ITearDownValidator seems to be missing.

Brian Kotek

unread,
Jan 6, 2013, 1:21:15 AM1/6/13
to swiz-fr...@googlegroups.com
Sounds like you're using an old version. There is no SwizMobile swc any longer. The current swc works in both mobile and desktop apps.

To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/UA3EpRCGkDcJ.

Dubnet

unread,
Jan 6, 2013, 8:04:13 AM1/6/13
to swiz-fr...@googlegroups.com
got it working - thanks for your help Brian

Payman Rezania

unread,
Jan 6, 2013, 7:46:01 PM1/6/13
to swiz-fr...@googlegroups.com
this has caused another issue in that I have an EventHandler in the view which is now no longer torn down. When the user navigates back to this view and performs an action which fires the event which is being listen to - the function gets called twice. 

What is the best way to handle this situation. What happens to the view if it is not torn down? When revisiting this view, does a new instance of the view get  created?

Your help is appreciated 

Brian Kotek

unread,
Jan 6, 2013, 9:33:13 PM1/6/13
to swiz-fr...@googlegroups.com
The best way to handle the situation is probably to let the view get torn down and then set back up when the user navigates back to it. If you have event handlers in it that you want to be triggered even while the view isn't on the screen, you should move that handler to another class (probably a presentation model).


To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/bN3xS8HD-asJ.

Payman Rezania

unread,
Jan 7, 2013, 5:12:53 AM1/7/13
to swiz-fr...@googlegroups.com
yes but that kinda takes to where I was at the start. I agree that a presentation model would help although I would need to do more reading around how to implement that.
 
to work with what i have currently, if i allow the view to get torn down (ie not extending the interface and implementing the allowTearDown) then the issue is that when the view gets revisited then the injected bean is not there (the model). What am I missing here? Would I need to inject the bean in again on addToStage or another way?

Brian Kotek

unread,
Jan 7, 2013, 9:44:37 AM1/7/13
to swiz-fr...@googlegroups.com
By default views are set up during addedToStage and torn down during removedFromStage. Have you tested things out using the latest Swiz swc to confirm that this is still an issue (since you were using an old version of the framework)? If so, I'd add your own listeners for addedToStage and removedFromStage to see if you can figure out what's actually going on. If navigating away from the view triggers removedFromStage (and the view is torn down), then something has to add it back to the stage again, meaning the view should be set up again.


To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/-Su08RsQTRoJ.

Payman Rezania

unread,
Jan 8, 2013, 3:16:38 AM1/8/13
to swiz-fr...@googlegroups.com
yes agreed this is why it is odd as Im assuming when a view gets set up the beans are injected as expected. The issue started when I added a transition to the navigator. This seems to be causing the issue. I will retest it with the new Swiz swc and see if it has made any difference. 

Payman Rezania

unread,
Jan 8, 2013, 3:40:09 AM1/8/13
to swiz-fr...@googlegroups.com
Hi Brian
This seems to have worked!
I have reverted back to my original set up but using the new Swiz swc and all the beans are getting injected properly when the user revisits views.
I love Swiz! but I feel like Im not using everything it has to offer - Im good with examples etc...are there any good books or examples (above whats there on Github)?

Brian Kotek

unread,
Jan 8, 2013, 9:29:44 AM1/8/13
to swiz-fr...@googlegroups.com
I think the docs cover everything fairly well: http://swizframework.jira.com/wiki/display/SWIZ/Home

There are no books out there, but as you said the examples repo on Github is there as well.


To view this discussion on the web visit https://groups.google.com/d/msg/swiz-framework/-/yj6X-Ds4NtIJ.
Reply all
Reply to author
Forward
0 new messages