• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call the creationComplete() method each time I visit the Flex state

 
Greenhorn
Posts: 9
Opera Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am facing a common problem, but somehow couldn't find any solution for that in net!!
We have an application where the front end is Flex. Here, after login, the user is given choice of 4-5 submodules where he/she can do some work. Now after doing changes in the screen, when ready, the user can opt for saving the changes he/she made or to "Spike" the workflow to discard all the changes made in the screen and taken back to the initial screen, where he/she was forwarded after the login.
So at this point, we want to destroy all the changes he/she made in the last session and when he/she selects the same submodule, all the pages/states will be loaded fresh.

But here, I realized that the creationComplete() method is not called again and the old pages (along with all the changes the user made in previous session) are re-loaded.

I tried to search for deleting Flex states/ creationPolicy = none and many other things to achieve this. But nothing is taking me nowhere.

Can anyone provide me some help please?

Here is the code I am using:

<mx:State name="Descriptions" id="descriptions" basedOn="Main">
<mx:AddChild relativeTo="{vbox1}" position="lastChild">
<components:moduleDescriptions id="desc" height="100%">
</components:moduleDescriptions>
</mx:AddChild>
</mx:State>
................ many other such states are there.

if the user select this sub-module:
else if ((menuMainModule.getFocus().tabIndex) == 4) {
currentState = 'Descriptions';
}

Here is code in moduleDescriptions.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
backgroundColor="#80D0CF" xmlns:components="com.test.myapp.view.*" creationComplete="init()">

private function init():void {
module = "DES";
userName = parentApplication.user.name;
..... other code to call the remote method and populate the data for the screen.
}

Now this is being called on the first time the application is loaded. Form next round, this method is not being called and the screen retains the old data.

This is driving me crazy. There has to be some way in Flex to clear the states/screen data and reload again. Someone please help me.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any reason you choose to use View States for this? It sounds like what you are after are distinct custom components you create and destroy as appropriate.

If you need to use states, could you not write your own reset method which is called on whatever event kicks of this process?

 
sankha ghosh
Greenhorn
Posts: 9
Opera Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Thanks for reply, but this one made me even more confused. I can explain what code I have written, but if now I need to explain.. why I have done it in that specific way..I don't think this thread will ever end.

In your reply, you have 2 questions and one assumption. Let me try to answer for each line:
1. To my limited Flex knowledge, I thought separate state for each submodule would be the best way to go.
2. I have many self coded components which represents these submodules. And once the user spikes or save a whole submodule, Yes, I want to destroy them and recreate them again for the new workflow.
3. This question is vague (I think you also never understood what you meant to say). Yes, I can write my own reset method, but all I want to do, is to call the creationComplete() method again to re-populate the data in the screen. That is the only thing I want to know in this post. Now if I knew how to do that, I would have written a "How-to" tech-blog instead of asking it here.

 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


To my limited Flex knowledge, I thought separate state for each submodule would be the best way to go.


This lumps your entire application into one component doesn't it? Have you looked at patterns like Cairngorm MVC or Pure MVC?


2. I have many self coded components which represents these submodules. And once the user spikes or save a whole submodule, Yes, I want to destroy them and recreate them again for the new workflow.


This sounds like you are using View States as a controller mechanism, which is probably beyond what they can really support (at least, for an applciation of any sophistication). I'd have a look at one of the patterns I mention above.


3. This question is vague (I think you also never understood what you meant to say). Yes, I can write my own reset method, but all I want to do, is to call the creationComplete() method again to re-populate the data in the screen. That is the only thing I want to know in this post. Now if I knew how to do that, I would have written a "How-to" tech-blog instead of asking it here.


What I meant is you seem to be trying to write logic based on a specific event which is not fired when you need it to be, so use a differernt event and call a custom reset method. Events are fired when states change, you could hook in to those. But unless your application is really simple, I would recommend restructuring it.
 
sankha ghosh
Greenhorn
Posts: 9
Opera Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again Paul,

Well, let me admit, No, I have not used any pattern like Pure/Cairngorm (because I don't have much idea about them). But then, I am not sure, what exactly you meant when you say "lumps your entire application into one component". Are you talking about the compiled output? In the flex project I have only one application Login.mxml and so I have Login.html and Login.swf file only for this project. Will that be a problem?
Now, regarding the event fire, When I am "Spiking" or cancelling all the changes I made, the objective is to clear all these components I created for each state. I should be return back to the base state, from where I can again resume selecting any submodule. Now I am able to track the spike event and clean up all the beans containing data which I populated when the application started. But in this second round , the creationComplete() methods are not doing anything. So I am curious to know of ways to re-invoke the init() method to re-populate the beans. My init() merthods contains the logic to populate data to be displayed in the screen.
Re-constructing at this point would be very difficult. Its a big and complicated application.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But then, I am not sure, what exactly you meant when you say "lumps your entire application into one component". Are you talking about the compiled output? In the flex project I have only one application Login.mxml and so I have Login.html and Login.swf file only for this project. Will that be a problem?


Well, its a fairly common pattern to split your swf into components that can be loaded on the fly to prevent the user having to down load one big swf when they are only going to use a small bit of it. View States use one big XML file, so you can't do this. If you are using them for a small bit of view logic this is OK, but if you are using them as your control mechanism for your whole app, this is probably bad.


I should be return back to the base state, from where I can again resume selecting any submodule. Now I am able to track the spike event and clean up all the beans containing data which I populated when the application started. But in this second round , the creationComplete() methods are not doing anything. So I am curious to know of ways to re-invoke the init() method to re-populate the beans. My init() merthods contains the logic to populate data to be displayed in the screen.


Can't you just hook into another event rather than creation complete? The user presumably does somthing with the UI, which will dispatch an event, you could just call your init methods from here. Or are you saying they care already called but do nothing second time around? If so you could try invalidationg the display list or something.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use:


In this way, init() is called each time the component "shows" on the display list.
 
sankha ghosh
Greenhorn
Posts: 9
Opera Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

Thanks for your tips and reply.

The great news is: I got the solution!!

I have used render event to track of any page loading (or rendering to be more specific) and used modelLocator pattern (Little bit of cairngorm) to identify the state change scenario. I am thinking of putting a more detail description here, once I get some time, so that anyone else like me can get some idea in this kind of scenario.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic