Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Author Topic: PureFormSubmission - Deferred Instantiation, StateMachine  (Read 5965 times)
Sr. Member
Posts: 86

View Profile Email
« on: June 17, 2009, 12:12:36 »

While trying to understand the StateMachine I've followed the instructions on PureMVC TV
( http://puremvc.tv/ )
and made a (very simple) FormSubmission application.
The app is also illustrating my experimenting with the deferred instantiation and the registration of puremvc mediators.
It is not a demo, so it is not commented at all.
There are 3 Views containing form-fields.(One, SubOne, SubTwo)
The data will be collected from all 3 forms when the user presses the submit button..

Feedback from the puremvc gurus, experts or anyone else would be much appreciated, especially because I'm still in the process of learning how to use the StateMachine  and therefore I need   suggestions for better solutions.

PureFormSubmission.swf  (demo)
PureFormSubmission.zip  (source)
http://code.google.com/p/ondina-air-flex-pmvc/source/checkout (source)

« Last Edit: July 02, 2009, 12:16:29 by Ondina » Logged

~ Ondina ~
Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #1 on: June 28, 2009, 09:52:46 »


I had a brief look but was a little confused about how it's supposed to work. Perhaps some info about what the happy path through this thing is supposed to be?

Sr. Member
Posts: 86

View Profile Email
« Reply #2 on: June 29, 2009, 09:16:50 »

Thank you Cliff for looking at that “thing”:)
As I said, it is not a demo, it is just an application that I used for experimenting with different puremvc aspects, so please excuse the layout and the lack of comments in the code.

I will try to keep this post as short as possible. I explained more on the Google site (urls below) and made some diagrams.

There are 2 things going on:
1. The registration of Mediators for Views in a ViewStack.
2. A StateMachine for a form submission based on the PureMVC TV - FSM .

1. There isn't much to see, except for the messages coming from mediators (onRegister) – similar to the SlackerDemo.  The difference between the SlackerDemo and my example consists in how I use the ChildExistenceChangedEvent and event.relatedObject to make the first View in the stack dispatch an event on creationComplete ( in order to register its Mediator)
You can see more details (explanation and diagram) here:
or  the entire code  here:

I don't know if this is a “clean” solution or not, but after trying to solve the issue of deferred instantiation of views in a  ViewStack and the registration of puremvc mediators in lots of ways, I decided to go with this one.  I can't have  a SplashView as in the SlackerDemo, meaning I can't have a View without a Mediator.
It would be nice if you could tell me if my solution is: very bad, bad, acceptable, good ...or if you'd give me some hints.

2. Now the StateMachine is the main reason I started the thread.
I took the FSM (Form Submission) from your presentation on PureMVC TV and modified it a bit.
My form consists of 5 input fields.  The input fields are scattered over 3 Views, which probably was confusing.
OneView: user-firstname, user-lastname, user-phone
SubOneView: user-sex
SubTwoView: user-language.

This diagram may help understand the structure of my scattered input fields:

The reason for having those scattered fields :
In my current project  I have several views in some ViewStacks. Each View has several input fields. A View represents a certain category of information, let's say in one view I collect user's personal data ,  in another View data about user's relatives, in another view health related data e.t.c
There are 2 situations I have to deal with:
1 the data from all  the Views has to be sent to the database, when the user hits the submit button
2 the data from a single View has to be saved separately
The Views have also their own VO.

In this example of mine I had only 5 input fields, just to keep it simple - in the beginning when I was trying to see how Notifications would work between different mediators.

Now the “happy path”:
The Form doesn't do much.  A click on the submit form button takes the app from the COLLECTING  state into the VALIDATING state. 
If the form is valid , the data is sent to the proxy and eventually to the database( I couldn't do that on the Google Site of course ) and if everything went well the app goes into the THANKING state.  If the form isn't valid (required fields still empty) a message about this fields appears in the middle of the app.The app is still in the VALIDATING state.
If you press the logout button while the app is still in the VALIDATING state, a confirm alert will appear  asking if you want to quit.
The reset button empties the fields.

The StateMachine Notification are on the bottom of the page. I know, it looks a bit odd, because I wanted to see all the stuff going on on exiting, entering, changed....

So the StateMachine in my example seems to be working, but somehow I have the feeling that there is something  I'm doing that is not quite right.

I tried to have the Validation happening on exiting from the COLLECTING state, as in your FSM. I could cancel the transition to the SAVING state, but then after a successful validation I couldn't  take the app into the SAVING state. It seemed to me as if the app was in no state. I surely did something wrong.
So I decided to have an additional VALIDATING state instead of the exiting thing.

Now, I hope very much that my long post and the stuff on the Google site were comprehensible and you can take a look at the FSM and code and tell me your opinion about it.

Thank you again for your presentation on PureMVC TV. I hope to see more of the like...
« Last Edit: July 02, 2009, 12:18:02 by Ondina » Logged

~ Ondina ~
Pages: [1]