3 Replies Latest reply on Oct 1, 2007 10:57 AM by Gyrfalc

    menubar - how to load from HTTP service

    Gyrfalc
      We're rewriting a legacy app that gets its menu structure from a database, since it is highly customized for each user (that part has to stay). I can't seem to get the correct combination of menubar dataprovider and *whatever* it needs to connect to so the menu gets built. I have the menu displaying correctly from just a static XML file (imported at compile time), but I need to get this menu hooked up to an HTTP service that is delivering the XML dynamically. I understand the HTTP service part, and that is all working fine, and I have dozens of them working with combo boxes and whatnot, but I can't figure out how to load the menu in this way. The XML coming back is just a "root" tag with a bunch of "menuitem" tags. I've tried event.result.root, event.result.root.menuitem, svc.lastResult, etc... all kinds of combinations, none of which seem to be the right thing. I saw somewhere in the documentation that it's supposedly doable, but can't find any examples. Thanks for any help!
        • 1. Re: menubar - how to load from HTTP service
          Gyrfalc Level 1
          Some semi-progress: I changed the XML structure so it now has a "root" tag, a "menuitem" tag for each of the top level items, and everything below that is a "children" tag. My data provider is {svc.lastResult.root.menuitem} . This built the correct structure, even disabling the correct items, but all the labels are [object Object]. If I ever figure out the secret handshake, I'll post it, but until then, if anybody knows the correct way to do this, that would be great. Thanks again.
          • 2. Re: menubar - how to load from HTTP service
            Gyrfalc Level 1
            Ok, found the problem. I had a labelField="@label" attribute in the menubar; removing this now displays the correct label. Plus, any items below the first level menu apparently must be named "children".

            <mx:MenuBar id="myMenuBar" showRoot="false" itemClick="itemClickHandler(event);">
            <mx:dataProvider>
            {svcMenu.lastResult.root.menuitem}
            </mx:dataProvider>
            </mx:MenuBar>

            And the XML returned from the server looks like this:
            <root>
            <menuitem label="Inquiry" id="r-inqry" enabled="true" auth="-1">
            <children label="Color Formula Inquiry" id="i-cfi" enabled="true" auth="2"/>
            <children label="Formula Inquiry" id="i-fi" enabled="true" auth="2"/>
            </menuitem>
            ...etc..
            </root>

            Where "id" and "auth" are custom attributes that I use elsewhere.

            The HTTP service looks like this, for those who are interested in this approach:
            <mx:HTTPService
            id="svcMenu"
            url="MenuCtrl"
            invoke="svcInvokeHandler(event);"
            result="svcResultHandler(event);"
            fault="svcFaultHandler(event);">
            <mx:request>
            <usrId>{theUser.usrId}</usrId>
            </mx:request>
            </mx:HTTPService>

            The menu data are stored in a hierarchical fashion in a database table, with a related table that assigns individual user permissions to the various menu items (that's the "auth" part).
            • 3. Re: menubar - how to load from HTTP service
              Gyrfalc Level 1
              One last thing... this menu handler example shows the correct syntax for retrieving any of the attributes of the menu item.

              // The event listener for the itemClick event.
              private function itemClickHandler(event:MenuEvent):void {
              var msg:String ="event.type: " + event.type;
              msg+="\nevent.index: " + event.index;
              msg+="\nItem id: " + event.item.id;
              msg+="\nItem auth: " + event.item.auth;

              Alert.show(msg);
              }