Re: [flexcoders] Re: Mate and sharing data across files
Aha! I had obviously missed the bit about the new User() when I was trying to adapt the example code. Sadly, today my flex2gateway has started throwing a 500 error again for no apparent reason so I can't test it until I figure out how to fix that. I really hate how flaky this thing is - apparently just turning your computer off for the night is enough to take it out even if you make no other changes. :( As for the CFC side of things, yes, the CFC does return a query object directly. I'd not realised that there was any other way to go about this. Like the idea of actually returning it as a User object, though. Once I get the flex2gateway issue sorted I'll have a play with this too. Thanks for the tip. :) Cheers, Seona. 2009/5/4 Tom McNeer tmcn...@gmail.com The first thing I see is that you have not declared thisUser as a new User. In your initial code, either do: public var thisUser:User = new User(); ...or in your function, do: thisUser:User = new User(); ... then follow with your thisUser.id code. Another suggestion, though. On the Flex side, you have a User class created to use as a VO: [Bindable] public class User ... but the result of your service call is expecting an ArrayCollection: public function login(userDetail:ArrayCollection):Boolean { if (userDetail.length 0) { thisUser.id = userDetail.getItemAt(0).id as Number; return true; } return false; } Is UserDetail really an ArrayCollection? What's happening in your CFC method? It appears as if you're passing a cfquery object, so I'm guessing you're doing a query based on the login information, and returning the query object directly. While that will work, you should think about having a matching User object the CF side. The signature needs to be the same as that of User.as, and User.as will need an alias statement at the top which refers to the CFC dot-delimited path. Check the CF docs about this. Fill the User.cfc with the data from your query, send the User object to Flex, and it will automatically be converted into an object of the User class. No ArrayCollection stuff. Alternatively, from your query, you can create a typed struct, which pretends to be a User.cfc. Like this: cfset userStruct = structNew() / cfset userStruct['__type__'] = path.to.User / (Note the two underscores on either side of 'type.') cfset userStruct['id'] = myQuery.id / ... and so on. Return the struct to Flex, and it will be typed as a User VO, populated from CF.
Re: [flexcoders] Re: Mate and sharing data across files
Thanks Tim. :) Finally gotten the chance to get back to this, and what you've said makes sense. Implementing it is proving somewhat troublesome, though. Still working with Cafe Townsend as my base, so I have a vos called User which looks like this: [Bindable] public class User { /*-.Properties..*/ public var id:Number; public var firstname:String; public var lastname:String; public var email:String; public var usertypeid:Number; /*-.Constructor..*/ public function User( id:Number = 0, firstname:String = , lastname:String = , email:String = , usertypeid:Number = 0 ) { this.id = id; this.firstname = firstname; this.lastname = lastname; this.email = email; this.usertypeid = usertypeid; } /*-.Methods..*/ public function copyFrom(newUser:User):void { this.id = newUser.id; this.firstname = newUser.firstname; this.lastname = newUser.lastname; this.email = newUser.email; this.usertypeid = newUser.usertypeid; } } I thought that was going to be fairly straight-forward to use, and implemented it in my UserManager as so: [Bindable] public var thisUser:User; public function login(userDetail:ArrayCollection):Boolean { if (userDetail.length 0) { thisUser.id = userDetail.getItemAt(0).id as Number; return true; } return false; } (Note that I've taken all of the other assignments out of this since they're currently commented out in my code anyway while I try and fix this one which is throwing the error). This gives me the error: TypeError: Error #1009: Cannot access a property or method of a null object reference. - MATE Error: Argument type mismatch, turn on the debugger for more information EventType:loginEvent. Error was found in a ServiceHandlers list in file MainEventMap - So I'm guessing this refers to the following in my eventMap: EventHandlers type={LoginEvent.LOGIN} RemoteObjectInvoker instance={userService} method=doLogin arguments={[event.username, event.password, _dsn]} debug=true resultHandlers MethodInvoker generator={UserManager} method=login arguments={resultObject}/ /resultHandlers /RemoteObjectInvoker /EventHandlers I'm just not sure what the problem actually is. If I take out the thisUser.id = etc line from the login function in the userManager and replace it with an alert of the result returned by the CFC, it works fine. So it seems to me it must be something to do with that assignment. Any ideas what it doesn't like about what I'm doing? Cheers, Seona. 2009/4/16 Tim Hoff timh...@aol.com ha, I was just kidding around about the freaking out thing. So, you're getting close, but I would do it this way: First, you only need a userManager. It is the model, so you don't need a userModel. The userManager would have a currentUser property. In your CFC result handler, call a method in the userManager that sets that currentUser to the lastResult. Next, create another currentUser property in any presentationModel that needs the data. Now, in your userMap, simply inject the currentUser from the userManager into the presentationModels. When a new user is set, to the currentUser in the manager, the presentationModels will be automatically refreshed; through injection. Injectors targets={ [ UserPresentationModel, AnotherPresetationModel ] } PropertyInjector targetKey=currentUser source={ UserManager } sourceKey=currentUser / /Injectors -TH
Re: [flexcoders] flex2gateway and proxies
Well, for completely unrelated reasons I've just flat-lined and reinstalled my PC. Now the flex2gateway works again. Go figure... Thanks for your reply anyway. :) ~Seona. 2009/4/20 Tom Chiverton tom.chiver...@halliwells.com On Monday 20 Apr 2009, Seona Bellamy wrote: Can someone please give me a step-by-step on what I need to do to make the flex2gateway work from behind a proxy? I know it's got something to do with Is this a proxy the client has between them and the internet, or one you have in front of your application ? In the latter case, nothing should need to be altered, as long as the proxy is able to simply forward requests to/from the application server.
[flexcoders] flex2gateway and proxies
Hi all, Hit a small bump in my learning curve. Actually, it's quite a big bump. Work has just made some substantial changes to the proxy server, and suddenly I've lost my flex2gateway. I get a 500 error when I browse to it. I did a bunch of hunting around on Friday and found some articles and forum threads, but nothing I tried seemed to work. Can someone please give me a step-by-step on what I need to do to make the flex2gateway work from behind a proxy? I know it's got something to do with the settings XML files, but none of the articles and threads I read seemed to agree on which ones, and some of the ones mentioned I don't even have! Cheers, Seona.
Re: [flexcoders] Mate and sharing data across files
To be honest, I'm not entirely certain. I've heard the word bandied around a bit, but I must confess that I don't fully understand what it means, what a singleton is, or how to identify if I've got them. I get the impression that they're something to do with an MVC approach, but I'm not 100% sure. Anyone here familiar enough with Mate and the attendant concepts to answer this one? Cheers, Seona. 2009/4/15 Tracy Spratt tspr...@lariatinc.com How does Mate handle data models? Does it use singletons? Tracy Spratt, Lariat Services, development services available
Re: [flexcoders] Re: Mate and sharing data across files
*grin* Thanks. I guess I was freaking out a little - I'd finally thought I was getting a handle on the whole Mate thing, and then I hit this problem and realised I was much further away from understanding than I thought. So let me see if I understand how this works, based on the examples I've seen: - I create a UserModel class which extends the InjectorTarget class. It has all of the user-related variables I want to pass around as bindable public variables, plus get and set functions. - As well as my regular Event Maps, I create a Model Event Map which has all of the different injectors that put data into the various models - When I perform the login function in the AuthorisationManager, the CFC returns me the details of the user who is logging in. I somehow call this UserModel and put all the data into the model's variables. - In the UserManager, when I want to run the GetKeywords function, for example, I can call on the data stored in the model to get the user's ID and pass it to the service I'm calling. Is that right? If it is, I think I need some help making the linkages between them all. I won't bother posting any code until I find out if I'm barking up the wrong tree, though. :) Thanks, Seona. 2009/4/15 Tim Hoff timh...@aol.com Hi Seona, Let's start by taking a deep breath and don't freak out. Ok, wheeew! Mate is a little different than typical MVC; in that it seperates the model into managers and presentation models (a manager holds data and a presentation model holds an instance of the needed data and controls constituant views). Let me elaborate a little, in that these two factions of the model are also smart models; they don't just sit by and hold data., they can also manipulate data/state as well. Yes, both managers and presentation models are singletons; thus they persist. If you place your user data in a userManager, then you can easily inject that data into whatever object you want, be it a view or a presentation model, via a map. I know that there aren't a lot of mate examples out there yet. But, please be patient; more are coming.. -TH
[flexcoders] Mate and sharing data across files
Hi guys, I'm not sure that the subject line is all that clear, but I honestly can't think of how best to express it. My brain's just really tied in a knot over this one. Bear with me for a moment and I'll try and explain where I'm coming from and what I'm trying to do. I'm pretty new to Flex as a whole, and have been trying to rework an existing app into the Mate framework. The original app was built when both myself and the other developer were just learning Flex (actually, we learned as we went along) and it quickly spiralled out of control into this complete nightmare of code. It's been decided that Mate is going to be our framework of choice for future Flex development, so I decided to start trying to rebuild our app in it as a learning exercise. I used the Cafe Townsend example ( http://mate.asfusion.com/page/examples/cafe-townsend) as a basis, and started off. So far so good - I managed to build a login interface, get the login function to call a CFC that looks up the details in the DB, and pass the user off to the main interface if they were in the DB. My problem now comes when I try to populate the main interface with the user's data. This would involve making more calls to other CFCs, passing them the user's ID, and getting back the records that are associated with the current user. The Cafe Townsend example didn't really help much with this, since once you're logged in you're logged in and it doesn't really do anything else with that information. I hunted around a bit and decided that the closest I could find to something that might do what I need is a Model and Injectors. The Weather Widget example ( http://mate.asfusion.com/page/examples/weather-widget) works with this, and I tried working it into what I had, but I suspect I've tied myself in a bit of a knot. Despite the fact that FlexBuilder is not flagging any errors, the app crashes the browser every time to try to run it. So I'm obviously doing something wrong. I just can't figure out what. So to summarise: how do I go about storing some data in such a way that it will be accessible to other parts of my application? For example, the user data that is brought back by an event in the MainEventMap needs to be visible to events in the UserEventMap. For that matter, are there any other decent examples out there besides the ones on the Mate website? Cheers, Seona.