You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by mateamargo <ma...@gmail.com> on 2007/04/25 19:35:21 UTC

InjectSpring and NullPointerException

I don't know if this should be asked here or in the SpringFramework forum.
I have a bean defined and I need to inject it into a property inside a class
that extends BasePage.

But when I read this property I get a NullPointerException.

Before that, I have tried without providing an implementation for that
setter (leaving it asbtract), but Tapestry complains.

So, what is the right thing to do?

@InjectSpring("somebean")
public abstract void SetSomething();

or

@InjectSpring("somebean")
public void SetSomething(SomeObject so){
    this.so = so;
}

Thanks.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10185808
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: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Alejandro Scandroli wrote:
> 
> I have no clue.
> Are you sure your spring context is ok? and is getting loaded?
> Have you tried with @InjectObject("spring:personDAObean")?
> Dough it should produce the same result
> 
> 

I know that it is loading fine because if I change something I get a bean
error.
I can't find the annotation @InjectObject, I guess is because I'm using
Tapestry 4.0.2.

Which version are you using?
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10190301
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: InjectSpring and NullPointerException

Posted by Alejandro Scandroli <al...@gmail.com>.
I have no clue.
Are you sure your spring context is ok? and is getting loaded?
Have you tried with @InjectObject("spring:personDAObean")?
Dough it should produce the same result


On 4/25/07, mateamargo <ma...@gmail.com> wrote:
>
>
>
> Alejandro Scandroli wrote:
> >
> > Hi MateAmargo
> >
> > just remove the property from the page definition
> > let the ".page" empty
> > <page-specification class="com.foo.PersonsList">
> > </page-specification>
> >
> >
> > Saludos.
> > Alejandro.
> >
>
> Hi Alejandro, I have just removed the property and now I'm trying to run
> Jetty...
> Nope, the same problem. I don't know why I get a NullPointerException.
>
> The object PersonDAO is a subclass of HibernateDAOSupport, and I don't know
> if it keeps null because a bad configuration or what.
> --
> View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10189304
> 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
>
>

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


Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Alejandro Scandroli wrote:
> 
> Hi MateAmargo
> 
> just remove the property from the page definition
> let the ".page" empty
> <page-specification class="com.foo.PersonsList">
> </page-specification>
> 
> 
> Saludos.
> Alejandro.
> 

Hi Alejandro, I have just removed the property and now I'm trying to run
Jetty...
Nope, the same problem. I don't know why I get a NullPointerException.

The object PersonDAO is a subclass of HibernateDAOSupport, and I don't know
if it keeps null because a bad configuration or what.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10189304
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: InjectSpring and NullPointerException

Posted by Alejandro Scandroli <al...@gmail.com>.
Hi MateAmargo

just remove the property from the page definition
let the ".page" empty
<page-specification class="com.foo.PersonsList">
</page-specification>


Saludos.
Alejandro.


On 4/25/07, mateamargo <ma...@gmail.com> wrote:
>
>
>
> Jessek wrote:
> >
> > Where are you getting that local member from ? You can't have anything
> > injected and used as a local member because the method you add the
> > annotation to will likely be replaced...So if you've been trying to set a
> > member and seeing it null that's why - it's not actually using your method
> > to inject it.
> >
>
> I just typed by memory, in fact it is:
>
> public List<Person> getPersons(){
>      return getPersonDAO().getAll();
> }
>
> @InjectSpring("personDAObean")
> public abstract PersonDAO getPersonDAO();
>
>
> I have added a .page file for this class with this:
>
> <?xml version="1.0"?>
>
> <!DOCTYPE page-specification PUBLIC
> "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
> "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">
>
> <page-specification class="com.foo.PersonsList">
>
>         <property name="personDAO" />
>
> </page-specification>
> --
> View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10187850
> 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
>
>

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


Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Jessek wrote:
> 
> Where are you getting that local member from ? You can't have anything
> injected and used as a local member because the method you add the
> annotation to will likely be replaced...So if you've been trying to set a
> member and seeing it null that's why - it's not actually using your method
> to inject it.
> 

I just typed by memory, in fact it is:

public List<Person> getPersons(){
     return getPersonDAO().getAll();
}

@InjectSpring("personDAObean")
public abstract PersonDAO getPersonDAO();


I have added a .page file for this class with this:

<?xml version="1.0"?>

<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN" 
"http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">

<page-specification class="com.foo.PersonsList">

	<property name="personDAO" />

</page-specification>
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10187850
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: InjectSpring and NullPointerException

Posted by Jesse Kuhnert <jk...@gmail.com>.
Where are you getting that local member from ? You can't have anything
injected and used as a local member because the method you add the
annotation to will likely be replaced...So if you've been trying to set a
member and seeing it null that's why - it's not actually using your method
to inject it.

On 4/25/07, mateamargo <ma...@gmail.com> wrote:
>
>
> public List<Person> getPersons(){
>     return PersonDAO.getAll();
> }
>
> This is because PersonDAO is null, and this is what I need to be injected
> by
> Spring.
> --
> View this message in context:
> http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10187525
> 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
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Santiago Fernández wrote:
> 
> Yes, you need a .page file, like every tapestry page. Or set the property
> "
> org.apache.tapestry.page-class-packages" in .application file.
> 
> Browse into the example:
> http://www.google.com/codesearch?hl=en&q=show:W7d5X-mFWSg:dORw9TpfYA4:F3TWNBX8eZ4&sa=N&ct=rd&cs_p=http://howardlewisship.com/downloads/tapestry-javaforge/tapestry-spring-1.0.0-src.zip&cs_f=tapestry-spring-1.0.0/src/test/webapp/WEB-INF/app.application
> 

I have used other classes without a .page file without problems.
But this I need a property to be injected by Spring and I'm not able to do
it.

The exception says that cannont read the "persons" OGNL:

<tr jwcid="@For" source="ognl:persons" value="person" element="tr">

The method getPersons:

public List<Person> getPersons(){
    return PersonDAO.getAll();
}

This is because PersonDAO is null, and this is what I need to be injected by
Spring.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10187525
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: InjectSpring and NullPointerException

Posted by Santiago Fernández <sa...@gmail.com>.
Yes, you need a .page file, like every tapestry page. Or set the property "
org.apache.tapestry.page-class-packages" in .application file.

Browse into the example:
http://www.google.com/codesearch?hl=en&q=show:W7d5X-mFWSg:dORw9TpfYA4:F3TWNBX8eZ4&sa=N&ct=rd&cs_p=http://howardlewisship.com/downloads/tapestry-javaforge/tapestry-spring-1.0.0-src.zip&cs_f=tapestry-spring-1.0.0/src/test/webapp/WEB-INF/app.application


2007/4/25, mateamargo <ma...@gmail.com>:
>
>
>
>
> Santiago Fernández wrote:
> >
> > This code works for me:
> >
> > public abstract class Home extends BasePage
> > {
> >
> >     ...
> >     @InjectSpring("someBean")
> >     public abstract SomeBean getSomeBean();
> >     ...
> >
> > Check this code:
> > http://www.google.com/codesearch?hl=en&q=+doc:9AU8EeUPIqc+%40InjectSpring%5C(+show:9AU8EeUPIqc:RIIGoLvmuBc:IOb23uxRU70&sa=N&cd=3&ct=ri&cs_p=http://howardlewisship.com/downloads/tapestry-javaforge/tapestry-spring-1.0.0-src.zip&cs_f=tapestry-spring-1.0.0/src/test/java/com/javaforge/tapestry/spring/pages/Home.java#a0
>
> >
> > Saludos
> >
> >
>
> But are you specifiying a .page file for that class?
> --
> View this message in context:
> http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10186909
> Sent from the Tapestry - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Santiago Fernández wrote:
> 
> This code works for me:
> 
> public abstract class Home extends BasePage
> {
> 
>     ...
>     @InjectSpring("someBean")
>     public abstract SomeBean getSomeBean();
>     ...
> 
> Check this code:
> http://www.google.com/codesearch?hl=en&q=+doc:9AU8EeUPIqc+%40InjectSpring%5C(+show:9AU8EeUPIqc:RIIGoLvmuBc:IOb23uxRU70&sa=N&cd=3&ct=ri&cs_p=http://howardlewisship.com/downloads/tapestry-javaforge/tapestry-spring-1.0.0-src.zip&cs_f=tapestry-spring-1.0.0/src/test/java/com/javaforge/tapestry/spring/pages/Home.java#a0
> 
> Saludos
> 
> 

But are you specifiying a .page file for that class?
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10186909
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: InjectSpring and NullPointerException

Posted by Santiago Fernández <sa...@gmail.com>.
This code works for me:

public abstract class Home extends BasePage
{

    ...
    @InjectSpring("someBean")
    public abstract SomeBean getSomeBean();
    ...

Check this code:
http://www.google.com/codesearch?hl=en&q=+doc:9AU8EeUPIqc+%40InjectSpring%5C(+show:9AU8EeUPIqc:RIIGoLvmuBc:IOb23uxRU70&sa=N&cd=3&ct=ri&cs_p=http://howardlewisship.com/downloads/tapestry-javaforge/tapestry-spring-1.0.0-src.zip&cs_f=tapestry-spring-1.0.0/src/test/java/com/javaforge/tapestry/spring/pages/Home.java#a0

Saludos


2007/4/25, mateamargo <ma...@gmail.com>:
>
>
>
>
> Santiago Fernández wrote:
> >
> > Hi, mateamargo. The getter
> >
> > @InjectSpring("somebean")
> > public abstract SomeBean getSomething();
> >
> > works fine... but be careful when you call getSomething()... if you call
> > this getter inside an "initialize()" method, you will get an exception,
> > because the property isn't injected yet... You must invoque this
> > property from a listener, or PageAttachListener.pageAttached()..
> >
> > Saludos desde Argentina :-)
> >
> >
>
> Ok, but If use an abstract method Tapestry complains saying that the
> method
> hasn't an implementation.
>
> Saludos che.
> --
> View this message in context:
> http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10186596
> 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: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Santiago Fernández wrote:
> 
> Hi, mateamargo. The getter
> 
> @InjectSpring("somebean")
> public abstract SomeBean getSomething();
> 
> works fine... but be careful when you call getSomething()... if you call
> this getter inside an "initialize()" method, you will get an exception,
> because the property isn't injected yet... You must invoque this
> property from a listener, or PageAttachListener.pageAttached()..
> 
> Saludos desde Argentina :-)
> 
> 

Ok, but If use an abstract method Tapestry complains saying that the method
hasn't an implementation.

Saludos che.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10186596
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: InjectSpring and NullPointerException

Posted by Santiago Fernández <sa...@gmail.com>.
Hi, mateamargo. The getter

@InjectSpring("somebean")
public abstract SomeBean getSomething();

works fine... but be careful when you call getSomething()... if you call
this getter inside an "initialize()" method, you will get an exception,
because the property isn't injected yet... You must invoque this
property from a listener, or PageAttachListener.pageAttached()..

Saludos desde Argentina :-)


2007/4/25, mateamargo <ma...@gmail.com>:
>
>
> I don't know if this should be asked here or in the SpringFramework forum.
> I have a bean defined and I need to inject it into a property inside a
> class
> that extends BasePage.
>
> But when I read this property I get a NullPointerException.
>
> Before that, I have tried without providing an implementation for that
> setter (leaving it asbtract), but Tapestry complains.
>
> So, what is the right thing to do?
>
> @InjectSpring("somebean")
> public abstract void SetSomething();
>
> or
>
> @InjectSpring("somebean")
> public void SetSomething(SomeObject so){
>    this.so = so;
> }
>
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10185808
> 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: InjectSpring and NullPointerException

Posted by Alex Fishlock <al...@racingjag.com>.
I am T5 sorry

-----Original Message-----
From: mateamargo [mailto:mateamargo@gmail.com] 
Sent: 25 April 2007 19:16
To: users@tapestry.apache.org
Subject: Re: InjectSpring and NullPointerException



Alex Fishlock wrote:
> 
> I use this with good results:
> 
> @Inject("spring:somebean")
> private SomeBean somebean;
> 

Without getter or setter?
Are you using a .page file for each class?
-- 
View this message in context:
http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html
#a10186539
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



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


Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.


Alejandro Scandroli wrote:
> 
> Hi Matecito ;-)
> 
> I'm using Tapestry 4.0.2, but @InjectSpring and @InjectObject
> annotations are not from Tapestry 4.0.2 core, they are from
> tapestry-spring module.
> Anyway, if when you change something you get a bean error it means
> that the problem is in other place. Are you sure that the NPE isn't
> happening inside PersonDAO?
> 
> Alejandro.
> 

Hi Ale, I have finally solved this by upgrading from 4.0.2 to 4.1 and that
was the only change.
I'm wondering if this is mentioned somewhere.

Thanks y gracias.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10204553
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: InjectSpring and NullPointerException

Posted by Alejandro Scandroli <al...@gmail.com>.
Hi Matecito ;-)

I'm using Tapestry 4.0.2, but @InjectSpring and @InjectObject
annotations are not from Tapestry 4.0.2 core, they are from
tapestry-spring module.
Anyway, if when you change something you get a bean error it means
that the problem is in other place. Are you sure that the NPE isn't
happening inside PersonDAO?

Alejandro.

On 4/26/07, Alex Fishlock <al...@racingjag.com> wrote:
> I am T5 sorry
>
> -----Original Message-----
> From: mateamargo [mailto:mateamargo@gmail.com]
> Sent: 25 April 2007 19:16
> To: users@tapestry.apache.org
> Subject: Re: InjectSpring and NullPointerException
>
>
>
> Alex Fishlock wrote:
> >
> > I use this with good results:
> >
> > @Inject("spring:somebean")
> > private SomeBean somebean;
> >
>
> Without getter or setter?
> Are you using a .page file for each class?
> --
> View this message in context:
> http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html
> #a10186539
> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: InjectSpring and NullPointerException

Posted by mateamargo <ma...@gmail.com>.

Alex Fishlock wrote:
> 
> I use this with good results:
> 
> @Inject("spring:somebean")
> private SomeBean somebean;
> 

Without getter or setter?
Are you using a .page file for each class?
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10186539
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: InjectSpring and NullPointerException

Posted by Alex Fishlock <al...@racingjag.com>.
I use this with good results:

@Inject("spring:somebean")
private SomeBean somebean;


----- Original Message -----
From: "mateamargo" <ma...@gmail.com>
To: users@tapestry.apache.org
Sent: 25 April 2007 18:35:21 o'clock (GMT) Europe/London
Subject: InjectSpring and NullPointerException


I don't know if this should be asked here or in the SpringFramework forum.
I have a bean defined and I need to inject it into a property inside a class
that extends BasePage.

But when I read this property I get a NullPointerException.

Before that, I have tried without providing an implementation for that
setter (leaving it asbtract), but Tapestry complains.

So, what is the right thing to do?

@InjectSpring("somebean")
public abstract void SetSomething();

or

@InjectSpring("somebean")
public void SetSomething(SomeObject so){
    this.so = so;
}

Thanks.
-- 
View this message in context: http://www.nabble.com/InjectSpring-and-NullPointerException-tf3646961.html#a10185808
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



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