Adobe Flex : how to have data shared between 3 tabs on a TabNavigator - actionscript-3

I have a tabbed dialog that has 4 tabs. The parent component is an mx:TabNavigator and each of the tab's views are custom MXML components inside an s:NavigatorContent. The data for 3 of the tabs has to be sent as one unit to a back end service. I'm trying to work out the best way to have the 3 tabs access the data that's to be sent down as one unit. I currently have one .mxml file that defines the top level mx:TabNavigator with each of the 4 tabs representing the s:NavigatorContent defined in it's own separate.mxml file to keep the file sizes fairly short. My current approach is to have each of the tabs load their data from the back end service in their creationComplete handlers and store it in a common class for the data model shared by the 3 tabs. This solution is OK except:
The creation complete handler for the first tab is called on application startup even though it's not the first visible component (i.e. there are other parts of the UI that the user sees first). I'd prefer to have true lazy loading where the data is not loaded until the tab becomes visible to the user.
If the user edits data on the first tab, then navigates to the second tab for the first time without hitting the apply button, changes made in the first tab are lost, because the creation complete handler of the 2nd tab will load the data model shared by the 3 tabs.
What I ideally want is:
True lazy loading; data is not loaded until the user clicks on a tab and it becomes visible.
Have it so that when the user hits apply on any of the 3 tabs the current entries on each of the 3 tabs is sent down to the back end service.
Thanks very much if anyone can advise on this. I can explain in further detail if needed.

I'm trying to work out the best way to have the 3 tabs access the data
that's to be sent down as one unit.
Best is always subjective. The easiest way is going to be to create a single variable for your shared data, and pass that instance into each relevant tab.
In some cases you may store the data in some central location, and the use Dependency Injection to inject that data into the relevant tab components that need it. Dependency Injection is implemented by a bunch of Flex frameworks, such as RobotLegs or Swiz.
An alternate option is to use a Singleton approach or static variables on a class to share the data between your multiple tabs.
My current approach is to have each of the tabs load their data from
the back end service in their creationComplete handlers
Why use creationComplete? The creationComplete event is fired after the component has completed it's layout routines and layout routines of it's children, and then everything is ready to use. I assume the act of loading more data, will force a lot of your components to have to go through their rendering process again. You may consider moving this into an earlier spot during the lifecycle, such as initialize or preinitialize.
1) The creation complete handler for the first tab is called on
application startup even though it's not the first visible component
(i.e. there are other parts of the UI that the user sees first). I'd
prefer to have true lazy loading where the data is not loaded until
the tab becomes visible to the user.
This would be expected behavior, based on the way that TabNavigators initialize. You can look at creationPolicy for more information. You can rewrite your 'load data' method to operate on the show method of the component, perhaps?
2) If the user edits data on the first tab, then navigates to the
second tab for the first time without hitting the apply button,
changes made in the first tab are lost, because the creation complete
handler of the 2nd tab will load the data model shared by the 3 tabs.
You can force a save of the data on the hide event of the component. Or possibly on the change event o the TabNavigator.

Related

List box is not updating in Windows Phone 8

I am developing one application, in that I have 3 pages. In first page I have List Box with some data and in 3rd page I have application bar for navigating to first page. I will get the list box data from the server. Whenever I am binding the List Box with server data, it is rendering properly but if the user navigate from 3rd page to 1st page using application bar then List box is not updating with fresh data, it is still displaying old data. If user comes to first page using back key press then new data is rendering.
I am using observable collection to bind List Box data and used NavigationService.Naviagte() for navigation.
Help me to resolve this issue.
Thanks in advance.
I am not very sure about your problem because you haven't cleared the whole context. But assuming that your data is refreshing on back key press, I can suggest you use NavigationService.GoBack() instead of NavigationService.Naviagte(). The former method call is equivalent to back key press. NavigationService.Naviagte() creates another instance of the page in the memory while NavigationService.GoBack() takes you back to the previous instance. Hope this helps.
As I understand everything is fine when you start. But the update is not happening upon second return, i.e. Through navigation.
My thought is that all your code to do this is in the constructor, and since the page is not removed from memory the constructor will not be called.
Two solutions move the code to a loaded event. Simply in the constructor write this.loaded += eventname;
Or you could put code in the onnavigatedto event. Write as a new function protected override onnavigatedto.
Putting it in the navigatedto, would probably make your app less responsive if you do server calls. If you have the code in the loaded event then the information will be uploaded when it is done. Which means the user will have a moment with old information. You could then introduce a waiting screen if it is an issue.

AngularJS : Dynamically update a JSON file and refeed autosuggest with it

Let's say I have a form for editing a furniture.
In my business logic, a furniture can have finishings.
In my ORM logic, "finishing" is a separate entity from "furniture", with a many-to-many relationship.
So in my "edit/furniture" form I present the user a "finishings" subsection,
with 2 UI (form) elements:
an autosuggest field, feeded by finishings.json (a file),
allows the user to attach already existing finishings to the furniture being edited,
a "+" button, that make fields appear, to enter one or more finishings.
allows the user to add finishings on the fly.
I want the user to be able to add finishings without leaving the "furniture/add[edit/$id]" REST url, so he doesn't experience a page reload.
To this end, I use the "form within form" trick, which means I'm not submitting the entire furniture form : I don't want the user to leave the page, nor do I want it to reload it. So the "submit new finishing" is a fake submit button that triggers the "finishing/add/" REST url. The REST part of the app is responsible for rewriting an updated finishings.json file that reflects the modified DB. Pretty standard stuff.
The real trick is : I would like the autosuggest field to reflect changes in realtime, doing this by "re-reading" the finishings.json file.
Here are 2 options:
Instead of the "form within form", I could just update the UI and push new finishings entries into a JSON object built upon the initial finishings.json file reading. I could push the new entries into this $scope object which would give the UI what it needs. Upon submitting the "edit furniture" form, I would prep data and sort stuff out: go through every finishing attached bu the user to the furniture, and separate the existing ones from the "just added" ones.
I keep my "form within form", because I want my finishings.json file, not a json object, to be the "source of truth".
I think I can manage option 1, but I'd really prefer to go with 2.
How would you do that?
What is the proper way in AngularJS to reload the finishings.json file on demand, and having it refeed the autosuggest with a fresh new batch of options, in real time?
Is the purpose of having this fresh data from the finishings.json file to enable every application user to be aware of new data in that file?
I mean... if me as user A am adding a new finishing, you want my finishing to be accounted by every other application user? Is that part of the suggestion algorithm?
If this is the case, and in fact what you're looking for is some sort of changes listener, you would have two options to solve this:
a) Using $timeout to pool the file every x seconds (I personally don't like this kind of approach).
b) Create a service that uses some form of WebSockets implementation (Socket.io, SignalR, etc). At an high level it would work this way: Your clients connect to the socket server/hub and subscribe to a data change event. Then, everytime a finishing is added to the file, you would then emit a data change event to the socket server which in turn would broadcast that event to every connected client.

How to do binding to Datacontext in different page

i have a textblock in mainpage.xaml. I have another page which has a textblock whose value is bound to observable collection and its value changes depending on user events on that page. How can i bind the textblock value in this other page to textblock value in mainpage.xaml?
Can anybody please guide me to any resources or examples which may explain how to do this or any workaround?
Well, you can't directly bind properties of two controls on different pages since they aren't displayed at the same time. You'll need to store your state elsewhere and retrieve the values from there.
Basically you'll need to store your application state somewhere, either inside the App class or singleton/static properties. Alternativelly you could persist the state between pages (to a file or setting) and retrieve it again when loading the page.
In any case you should bind the controls in both pages to a view model which would retrieve the values from the application state or itself be stored there. This way the values set from one page will reflect on the other one.
Depending on how you navigate between pages you might be able to take advantage of parameters as well (Frame.Navigate(typeof(OtherPage), parameter)) but you're limited to tranferring only basic types this way, so you'll be able to transfer ids but not complete objects.

Design Pattern to require multiple events before executing method?

There are many times that I've needed to execute some code after a number of events have fired, and I've come up with counters and such but I feel there must be a better way.
For example, say five files need to be loaded, after which a UI component will become active.
If I set up a counter that increments each time a file is requested, then decrements each time one has loaded, I run the risk that the first two or three files may somehow get completely loaded before my code gets around to requesting the fourth and fifth, which would mean that my counter would be at zero when I still have two files to load, thus allowing the UI component to be prematurely activated.
There are some cases where you could know the number that need to be loaded before the requests go out, but it's possible that the first file contains the paths (and therefore the number of) files. (And this file-loading scenario is only an example of the pattern I'm trying to explain.)
Does anyone have an elegant solution for this? (Does my description make sense?) Thanks!
You could do something with a task framework like spicelib
Using that as an example
Create a FileRecursionLoadTask which grabs a file and completes when that file and any references it makes are loaded.
Add each FileRecursionLoadTask to a SequentialTaskGroup.
When the TaskGroup is completed, then you know all of the file loads have completed.
There are also plenty of other task frameworks which you might like better. For example, Spring ActionScript also has one.
Before executing a request, store a reference (a unique request uri, the loader object or a special command object) in a list. When a loader has finished, remove that object and call a function that checks if there are remaining active tasks in the list.
This isn't specific to file requests nor request in general, it can be used for anything that needs to wait for multiple actions to finish. Multiple list can be used to process multiple types of action at the same time. The object stored in the list could be implemented as a command object, which could provide more information about the task. This is called command pattern.
If you're doing just loading, like Jacob, I would also suggest a library that handles loading
If the case of a more complicated situation like mixing loaders and other event listeners, I would suggest using an event that fires whenever there is any change to any of the dependencies. In addition all the objects/classes would have a state.
Then I would create a listener adding function for the class that would need to do the function or initiate it, that would have 3 parameters
object with event dispatcher (assuming they all use the same update event) ie. assetLoader
name of object state ie. headerLoaded
state value's desired ie. true
the function would add the listener to a chain of listeners, and any time any of the listeners fires, all objects would check if the state value.
This would allow for regression as well (like when a user presses a button, the content starts loading, but then the user presses cancel, even if all the assets load, the state of one object would be false, thus not allowing the item to complete) If you were using counters, it would be the equivalent to adding instead of subtracting, but much more reliable.
Looking for a design pattern? Try the command pattern (http://johnlindquist.com/2010/09/09/patterncraft-command-pattern/)
(The video is a great example of what command pattern is and how it works - using Starcraft as an example.
The implementation is that you queue your load commands so that they do not execute out of order, and you can add the enable or disable commands to your command que. So the command pattern will play back your commands something like: load, load, load, enable ui item, load, load, enable another item
Good luck

First page of MS Access Report does not seem to call On Page Event

I have coded a MS Access 2000 report that displays a calendar with one month per page and projects added to particular days. The only data in the underlying record source is a list of months. The structure is created via the On Page event, which also reads in other data.
When this report is opened, I've noticed that the On Page event does not seem to be triggered for the first page. (I attribute this to the fact that On Page in reports is activated when a page is cached rather than when a page is displayed, such as On Current for Access forms.)
When the report is displayed my work around is to use the On Activate event to force the On Page subroutine to run even though that event has not been called. However when the report is exported it does not trigger the On Activate event and the first page of the export is in one of two formats:
1) if the report was open in Access (ie On Activate had been triggered previously) the first page is identical to either the page after the one being displayed or the last page, except with the correct month (which comes from the underlying record source)
2) if the report was not open in Access the first page contains just the structure within the report design view (ie lots of empty boxes)
My best workaround is to force a (otherwise pointless) cover page to ensure the first page contains nothing that needs code to run, but this is far from ideal. Can I force the code to run for the first page of an export? Or maybe I'm misunderstanding how On Page works and I need to restructure my code? (I've also noticed that On Page seems to run twice for the last page).
I would recommend restructuring your code so that you build your data in one query, multiple queries, or in VBA, and then open the report with the new datasource. I might still have Access 2000 at home to check, but at work I can test both 2003 and 2007, and in both versions, the OnPage event fired before each page was displayed. If you are experiencing different behavior, I suspect it's because Access isn't sure how to handle what you are asking it to do.
Typically a report like the one you are describing would be designed the other way around: the datasource for the report would contain all the project information. Is there something about the data you're trying to display that prevents you from building a query that would contain all of it?
Have you considered the Format event for the various sections, especially the Detail section? Format or Print are a more usual events for manipulating reports.