Do u see the DAO being created when the application goes up? Tapestry
does a very good job informing all the services that are configured.
If it's not in the log then u r not binding the service.
There r 2 ways to bind services in a module:
public static void bind(ServiceBinder binder) {
binder.bind(Interface.class, Impl.class);
}
or
public static Interface buildServiceName()
{
return new InteraceImpl();
}
I really didn't get what u were trying to do in the first email.
ApplicationStateCreator<IAccount> account =
new ApplicationStateCreator<IAccount>(){
public IAccount create() {
return new AccountDAO();
}
};
configuration.add(IAccount.class, new
ApplicationStateContribution("session", account));
in what method of ur App module is that code?
On Mon, Aug 3, 2009 at 9:35 PM, neo
anderson<[email protected]> wrote:
>
> Thanks for reply.
>
> I am a bit confused now. Would you please give a bit more explain on how to
> add make AccountDAO a service?
>
> Why I am confused is because I discover when I switch back using the old
> testing code, it works correctly. The way how I obtain the AccountDAO is
>
> in Login.java
>
> �...@inject
> private IAuthService auth;
>
> Object onSubmitFromLogin(){
> ...
> user = auth.authenticate(new User("-1", this.account, "",
> this.password));
> ...
> }
>
> in AppModule.java
>
> public static void bind(ServiceBinder binder) {
> binder.bind(IAuthService.class, AuthService.class);
> binder.bind(IAccount.class, Account.class);
> }
>
> in AuthService.java
>
> �...@inject
> private IAccount accountDAO;
>
> public User authenticate(User user){
> ...
> User u = accountDAO.findUserByAccount(account);
> ...
> }
>
> Then when accessing the login page from web, everything works fine (the
> accountDAO is not null).
>
> But when switching using one that integrates JAAS then the accountDAO
> becomes null. For instance, in AuthService.java the code switch to use
> RdbmsLogin.java where injecting accountDAO (@Inject private IAccountDAO)
>
> in AutheService.java
>
> public User authenticate(User user){
> ...
> RdbmsCallbackHandler handler =
> new RdbmsCallbackHandler(account, password);
> try{
> LoginContext context =
> new LoginContext(JAAS_REALM, handler);
> context.login();
> }catch(LoginException le){
> le.printStackTrace();
> }
> ...
> }
>
> in RdbmsLogin.java
>
> public class RdbmsLogin implements LoginModule{
> public boolean login() throws LoginException {
> ...
> flag = validate(account, password);
> ...
> }
> private boolean validate(String account, String password){
> ...
> // the accountDAO is always null here, but the accountDAO
> injected inside
> the AuthService is not null.
> User user = accountDAO.findUserByAccount(new User("-1",
> account, "",
> password));
> ...
> }
>
> Or if I simply replace AuthService with RdbmsLogin, the AccountDAO injected
> inside RdbmsLogin is still null.
>
> What additional setting I need to configure?
>
> Thanks for patiently answering my questions.
>
> I appreciate it.
>
>
> Thiago H. de Paula Figueiredo wrote:
>>
>> Em Mon, 03 Aug 2009 13:03:51 -0300, Neo Anderson
>> <[email protected]> escreveu:
>>
>>> The problem is that it looks like accountDAO is always null. It seems to
>>> me that the IAccount does not successfully bind with AccountDAO class;
>>
>> It wasn't, unless you add make AccountDAO a service. Just instantiating it
>> and using as part of the configuration of another service doesn't make it
>> a service.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java consultant, developer, and instructor
>> http://www.arsmachina.com.br/thiago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Tapestry-5-IoC-binding-interface-with-impl-problem-tp24793396p24796853.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]