You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/12/13 10:18:06 UTC

T5: why injected globals always null?

Hi,
I have this service as follow, and I can see it 'defined' in the
servicestatus, but when use in a page, the variable globals is always null,
why?

public interface EMailer {
    public String smtpHost();
}

public class EMailerImpl implements EMailer {

    @Inject private ApplicationGlobals globals;
    public String smtpHost() {
        return globals.getServletContext().getInitParameter("smtp_host"); //
globals always null, why?
    }
}

In a page:

  @Inject
  private EMailer eMailer;

    public void onActivate(Object[] obj) {
        _objs = obj;
        if (obj.length > 0) {
        }
        System.out.println(eMailer.smtpHost());
    }

-- 
View this message in context: http://www.nabble.com/T5%3A-why-injected-globals-always-null--tp14312420p14312420.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


RE: T5: why injected globals always null?

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,
Thanks.


kristian.marinkovic wrote:
> 
> the @Inject annotation works only in pages.... 
> not in other services!!
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-why-injected-globals-always-null--tp14312420p14312969.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


RE: T5: why injected globals always null?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
the @Inject annotation works only in pages.... 
not in other services!!

if you need to inject a service into another service 
define it in the constructor or set it in your builder method

see http://tapestry.apache.org/tapestry5/tapestry-ioc/
and there have been some new articles on ioc usage
in the wiki

g,
kris





Angelo Chen <an...@yahoo.com.hk> 
13.12.2007 10:18
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
T5: why injected globals always null?








Hi,
I have this service as follow, and I can see it 'defined' in the
servicestatus, but when use in a page, the variable globals is always 
null,
why?

public interface EMailer {
    public String smtpHost();
}

public class EMailerImpl implements EMailer {

    @Inject private ApplicationGlobals globals;
    public String smtpHost() {
        return globals.getServletContext().getInitParameter("smtp_host"); 
//
globals always null, why?
    }
}

In a page:

  @Inject
  private EMailer eMailer;

    public void onActivate(Object[] obj) {
        _objs = obj;
        if (obj.length > 0) {
        }
        System.out.println(eMailer.smtpHost());
    }

-- 
View this message in context: 
http://www.nabble.com/T5%3A-why-injected-globals-always-null--tp14312420p14312420.html

Sent from the Tapestry - User mailing list archive at Nabble.com.


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