Hi

I encounter a problem. My problem is when I use @ApplicationState (e.g. 
@ApplicationState private IAccount account;) to obtain a mock object, which 
contains user/ account information, the system will complains 
NullPointerException.

My purpose is to create LoginForm;  so when user enters id/password, the system 
will verify it. The login Form looks like: 

Login.tml
<t:form t:id="login">
...
<input type="text" t:id="account" t:type="TextField" t:value="account"/>
...
<input type="text" t:id="password" t:type="PasswordField" t:value="password"/>
...
</t:form>

The Login.java will obtain id/ password and use a service to authenticate 
whether the id/ password exists in the datasource (a mock object). 

public class Login {
...
        private static LoginService security = new LoginService();
...
        @ApplicationState
        private User user;
...
        Object onSubmitFromLogin(){
                user = security.authenticate(getAccount(), getPassword());      
                return index;
        }
}

In LoginService.java, it contains mock object, which has registered using 
AppModule services. 

public class LoginService{

        @ApplicationState
        private IAccount account;

        public User authenticate(String email, String password){
                User u = account.findUserByAccount(email); // the error occurs 
at here because account is always NULL!
                if(password!=null && password.equals(u.getPassword())){
                        return u;
                }
                return null;
        }
}

AppMoudle.java registers IAccount as a service. Indeed, another registered 
object ICatalogue works without a problem; and after app is launched, there is 
no error saying any failure related to IAccount service. 
...
        public void 
contributeApplicationStateManager(MappedConfiguration<Class, 
ApplicationStateContribution> configuration){
                ApplicationStateCreator<ICatalogue> catalogue = 
                        new ApplicationStateCreator<ICatalogue>(){
                                public ICatalogue create() {
                                        return new Catalogue();
                                }
                        };
                ApplicationStateCreator<IAccount> account = 
                        new ApplicationStateCreator<IAccount>(){
                                public IAccount create() {
                                        return new Account();
                                }
                        };
                configuration.add(ICatalogue.class, new 
ApplicationStateContribution("session", catalogue));
                configuration.add(IAccount.class, new 
ApplicationStateContribution("session", account));
        }
...

Is is because the IAccount does not include in the Page folder? Or what might 
cause such problem?

Thank you very much,

/arsene




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to