4 Replies Latest reply on Aug 25, 2008 8:27 PM by Ratsnackbar

    HTTPService Help!

      Hi All! :D

      I have a program where a user will search for something and the results will be shown in a DataGrid. I use HTTPService and arrayCollection to implement this. (I use flex only as my front end. There is a java program behind that is responsible for searching). Upon clicking a column they will be redirected to another page. This page contains all the information about the entry that was clicked. My problem is this: I have a button named "Return to search results" that when clicked it should go back to the previous page with the search results still shown in the DataGrid but I do not know how to do this. How to implement this?

      Any help will be greatly appreciated.

      Thanks :D
        • 1. Re: HTTPService Help!
          Ratsnackbar Level 2
          Actually it sounds like perhaps you need to think of changing the UI a little. It would seem better to my in this situation to open a new Modal panel with the details of the item clicked rather then switching screens.

          For example you start with your datagrid as the background layer and on each click open a new TitleWindow that when closed just leaves you at the same DataGrid that has never changed.

          At the very least you would want to use a ViewStack and change views based on the selected item. When closing the item you would just remove that one view leaving you back at your main DataGrid view. In this instance you would only ever have two objects in the ViewStack.

          As for your current problem perhaps I am misunderstanding. Are you stating that when returning to the DataGrid it is loosing it's data?

          Generally speaking you would want to make your initial call to the HTTPService only on the creationComplete() event of the DataGrid or it's container. Then only trigger further calls to the HTTPService based on certain events such as the click of a Refresh button. The Datagrid would be bound to your dataprovider and the dataprovider would only get changed upon successful return of the HTTPService call. If this is what you are doing then there is no reason this should get cleared by just switching view objects in a view stack or windows. Just make sure not to clear your dataprovider unless you really really want to or upon closing the main view.
          • 2. Re: HTTPService Help!
            bitwyse Level 1
            Hey Jugger,

            I have an application I'm working on that does exactly the same thing. I am using a ViewStack to accomplish what you are looking to do. There are other ways to do it for sure, I personally like the ViewStack. One of the other ways to do this would be to use States. I am not a big fan of States, however, it's due to my lack of experience with them. Maybe someone else can chime in on States or other ways to help.

            • 3. Re: HTTPService Help!
              JuggerOgre Level 1
              Hi Ratsnackbar :D

              Yep it is losing data when I return to the search results page. The Data Provider for my datagrid is a variable I declared in a script. I declared it as an ArrayCollection. I am not clearing it in any way when I return to the search/results page.

              About your first recommendation I think it is a great idea but sadly I cannot change the UI. :(
              • 4. Re: HTTPService Help!
                Ratsnackbar Level 2
                "...but sadly I cannot change the UI. :("

                Ah Bummer.

                "The Data Provider for my datagrid is a variable I declared in a script."

                Just to be clear do you mean you defined it in a script block (I.E. <mx:Script>) or in a function?

                You would want to make sure to declare your dataprovider in the beginning of your scriptblock and just below the import statements.

                <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="initApp();">
                import mx.collections.ArrayCollection;

                [Bindable] private var myDP:ArrayCollection;

                private function initApp():void{

                private function getData():void{
                //Set Event Handlers and then make
                //HTTPService, WebService or RemoteObject call

                private function dataResult(event:ResultEvent):void{
                myDP = event.result as ArrayCollection;

                private function dataFault(event:FaultEvent):void{
                //custom fault handler code

                private function refreshGrid(event:Event):void{
                //test which control the user interacted with and then
                //do something different based on the target or
                //simply call

                <mx:VBox left="0" top="0" right="0" bottom="0">
                <mx:DataGrid id="myDataGrid" dataProvider="{myDP}" width="100%" height="100%">
                <mx:Button id="refreshGridBtn" label="Refresh" click="refreshGrid(event);" />

                Of course this code is not complete or tested in any way but you get the point. Once this component is initialized and the creation complete it loads it's data. The data never gets unloaded (only refreshed) during the life of the component.

                Because it is a Canvas component housing your DataGrid you can simply add it to a View stack as the first child. It would be easy enough to create another custom canvas for your details view.

                You would want to bind your details view to the selectedItem of the dataGrid or make a call for more data based on it's id perhaps.

                To change views you could simply add and remove children from the viewstack or even create only a single instance of a details view which sites behind the datagrid view and then toggle the index upon selecting an item from the grid and back again when the user clicks close on the detail view.

                {Sorry, not much of an explanation I realize. I just don't have time right now to whip out an example.}