You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ashwanth Kumar <as...@gmail.com> on 2009/12/17 13:09:09 UTC
Help with @Inject in onEvent Handler Object
Hi,
I've a problem. I'm using a page which has an actionlink like this:
<a t:type="actionlink" t:id="alid">Link Text</a>
And i've an @OnEvent handler in my Page Class, as follows:
@OnEvent(component="alid")
void function() {
DBConnect db = new DBConnect();
System.out.println(db.getLine());
}
Till, this i've no problem. I've an object called DBConnect which has the
class as follows:
public class DBConnect {
@Inject
Session _session;
public String getLine() {
* List _news = _session.createCriteria(RNews.class).list();*
return _news.getText();
}
}
When i run the actionlink, i get an NullPointer Exception at the bolder line
above (at the _session.createCriteria(RNews.class).list()).. Why does this
happen? Isn't this mean, @Inject is not working, hence the _session is not
initialized??
- Ashwanth Kumar
Re: Help with @Inject in onEvent Handler Object
Posted by Ashwanth Kumar <as...@gmail.com>.
Hey Thanks Guys!
Its working cool!
- Ashwanth Kumar
On Thu, Dec 17, 2009 at 6:21 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> Em Thu, 17 Dec 2009 10:17:15 -0200, Joost Schouten (ml) <
> joost_ml@jsportal.com> escreveu:
>
>
> Your DBConnect object is probably not in one of the tapestry controlled
>> packages and thus inject doesn't work. You can inject the Session directly
>> into your page, or turn your DBConnect object into a tapestry service by
>> adding it to the services package, and changing the Session into a
>> constructor argument.
>>
>
> You can also declare DBConnect as a Tapestry service. Doing this, you can
> @Inject DBConnect and the @Inject annotation inside it will work.
>
> In your AppModule, add this method if you don't have it already:
>
> public static void bind(ServiceBinder binder) {
> binder.bind(DBConnect.class);
> }
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Help with @Inject in onEvent Handler Object
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 17 Dec 2009 10:17:15 -0200, Joost Schouten (ml)
<jo...@jsportal.com> escreveu:
> Your DBConnect object is probably not in one of the tapestry controlled
> packages and thus inject doesn't work. You can inject the Session
> directly into your page, or turn your DBConnect object into a tapestry
> service by adding it to the services package, and changing the Session
> into a constructor argument.
You can also declare DBConnect as a Tapestry service. Doing this, you can
@Inject DBConnect and the @Inject annotation inside it will work.
In your AppModule, add this method if you don't have it already:
public static void bind(ServiceBinder binder) {
binder.bind(DBConnect.class);
}
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Help with @Inject in onEvent Handler Object
Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
Your DBConnect object is probably not in one of the tapestry controlled
packages and thus inject doesn't work. You can inject the Session
directly into your page, or turn your DBConnect object into a tapestry
service by adding it to the services package, and changing the Session
into a constructor argument.
Hope this helps,
Joost
Ashwanth Kumar wrote:
> Hi,
>
> I've a problem. I'm using a page which has an actionlink like this:
>
> <a t:type="actionlink" t:id="alid">Link Text</a>
>
> And i've an @OnEvent handler in my Page Class, as follows:
>
> @OnEvent(component="alid")
> void function() {
> DBConnect db = new DBConnect();
> System.out.println(db.getLine());
> }
>
> Till, this i've no problem. I've an object called DBConnect which has the
> class as follows:
>
> public class DBConnect {
> @Inject
> Session _session;
>
> public String getLine() {
> * List _news = _session.createCriteria(RNews.class).list();*
> return _news.getText();
> }
> }
>
> When i run the actionlink, i get an NullPointer Exception at the bolder line
> above (at the _session.createCriteria(RNews.class).list()).. Why does this
> happen? Isn't this mean, @Inject is not working, hence the _session is not
> initialized??
>
> - Ashwanth Kumar
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org