Model is null when I try and use it later in the service
Hi all,
For some reason my userModel is null when I try and use it later in the service
public class AuthenticationService extends Actor implements IAuthenticationService
{
[inject]
private var userModel:UserModel;
private function resultHandler(event:ResultEvent):void
{
CursorManager.removeBusyCursor();
if (event.result.length == 1){
var test:Object = event.result[0];
var user:User = new User;
user.email = event.result[0].mail;
user.name = event.result[0].name;
user.SAMAccountName = event.result[0].SAMAccountName;
user.commentsUsersSelect = event.result[0].commentsUsersSelect;
user.commentsView = event.result[0].commentsView;
user.ratingsView = event.result[0].ratingsView;
//just update the model here instead of calling a command
userModel.loggedInUser = user;
dispatch(new UserEvent(UserEvent.USER_LOGIN,user));
}
}
configured here:
public class ConfigureModelCommand extends Command
{
override public function execute():void
{
injector.mapSingleton(CommentsModel);
injector.mapSingleton(UserModel);
dispatch(new ApplicationConfigurationEvent(ApplicationConfigurationEvent.CONFIGURE_VIEW));
}
}
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Stray on 04 Oct, 2010 05:14 PM
Hi Nikos,
Injected values have to be public - yours is private :)
An easy mistake to make, and an easy fix too!
Stray
Support Staff 2 Posted by Ondina D.F. on 04 Oct, 2010 05:27 PM
After doing what Stray said, you'll have to fix the [Inject] tag too :)
Wrong:
[inject]
[InJect]
[INJECT]
Right:
[Inject]
public var someClass:SomeClass;
Ondina
3 Posted by Stray on 04 Oct, 2010 05:33 PM
Well spotted! I was so distracted by the private I didn't even check the spelling of [Inject].
4 Posted by Nikos on 05 Oct, 2010 08:25 AM
haha woops, btw why is it that vars need to be public?
5 Posted by Stray on 05 Oct, 2010 08:31 AM
Just because if they were private the injector wouldn't be able to access them. The actual method of setting values is subject to the same rules as usual.
The alternative is setter injection - private var, and a public setter func, marked with inject.
Shaun Smith closed this discussion on 01 Nov, 2010 10:51 PM.