You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Neo Anderson <ja...@yahoo.co.uk> on 2009/05/22 18:14:24 UTC
[T5] Error obtaining ApplicationState object
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5] Error obtaining ApplicationState object
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 22 May 2009 13:14:24 -0300, Neo Anderson
<ja...@yahoo.co.uk> escreveu:
> Hi
Hi!
> public class LoginService{
>
> @ApplicationState
> private IAccount account;
You can't use @ApplicationState (deprecated because of misleading name,
now use @SessionState instead, works exactly the same) in services, just
in pages, components and mixins. Use the ApplicationStateManager service
instead.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org