You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andrew B <ch...@yahoo.com> on 2005/10/30 17:59:02 UTC

Injecting Spring beans into page class

Hi,

I have a Tapestry 4/Spring/Hibernate application, and
I would like to inject a dependency into a page class,
that Tapestry then calls to render a page. 

The page class is Home, and the dependency is
invoiceDao.  In my applicationContext I have:

<beans>
        <bean id="Home" class="com.mypackage.Home">
        	<property name="invoiceDao">
        		<ref bean="invoiceDao"/>
        	</property>	        
        </bean>

        <bean id="invoiceDao"
class="com.mypackage.dao.InvoiceDao">
        	<property name="hibernateTemplate">
        		<ref bean="hibernateTemplate"/>
        	</property>
        </bean>
......
</beans>

This works, but then I can't tell Tapestry to get the
Home object from Spring, so it creates its own, that
has not had the dependency injection. The predictable
result is a NullPointerException when I try to access
invoiceDao.

Can I even do it this way, or do I have to let
Tapestry create the Home object, and then "dependency
suck" the DAO from Spring using the
ApplicationContext? (I want to avoid this, as it
defeats the purpose of dependency injection).

Yes, I have read the page out there that describes how
to integrate the two (can't remember the URL, but it's
the one that tells you to set up a HiveMind module to
patch in Spring, and gives an example of injecting a
Spring property into the page like this: <inject
property="home" object="spring:Home" />).

Any help is appreciated, thanks.

Andrew Broderick


	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

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


Re: Injecting Spring beans into page class

Posted by Andrew B <ch...@yahoo.com>.
Thank you!!! Exactly what I needed. It now works
great, and I can go and show my boss the app tomorrow
as a proof-of-concept of using Spring, Hibernate and
Tapestry together, so that we can get out of doing web
development in the stone age.

--- Ron Piterman <rp...@gmx.net> wrote:

> Tapestry Annotations are an *alternative* to the xml
> in the .page/.jwc, 
> so you can do everything either with annotations or
> with xml -
> 
> in this case:
> 
> <inject object="spring:InvoiceDao"
> property="invoiceDAO"/>
> 
> and in your page class :
> 
> public abstract DAO getInvoiceDAO();
> 
> 
> then use the abstract method normally,
> 
> Cheers,
> Ron
> 
> 
> 
> ציטוט Andrew B:
> > I have tapestry-spring.jar, and have read the wiki
> > page. The last thing the wiki says is how to
> inject a
> > Spring bean into the page, not the page class.
> > 
> > Is using the annotation
> > @InjectObject("spring:InvoiceDao")
> > the only way to do it? The reason I ask is that I
> am
> > trying to avoid having to use JDK1.5 if possible,
> for
> > compatiblity with deployment environments. But, if
> > that's the only way to do the dependency
> injection,
> > then that's what I'll have to do.
> > 
> > Thanks
> > 
> > 
> > --- Oliver Lietz <ta...@oliverlietz.de> wrote:
> > 
> > 
> >>Am Sonntag, 30. Oktober 2005 17:59 schrieb Andrew
> B:
> >>
> >>>Hi,
> >>>
> >>>I have a Tapestry 4/Spring/Hibernate application,
> >>
> >>and
> >>
> >>>I would like to inject a dependency into a page
> >>
> >>class,
> >>
> >>>that Tapestry then calls to render a page.
> >>>
> >>>The page class is Home, and the dependency is
> >>>invoiceDao.  In my applicationContext I have:
> >>>
> >>><beans>
> >>>        <bean id="Home"
> >>
> >>class="com.mypackage.Home">
> >>
> >>>        	<property name="invoiceDao">
> >>>        		<ref bean="invoiceDao"/>
> >>>        	</property>
> >>>        </bean>
> >>>
> >>>        <bean id="invoiceDao"
> >>>class="com.mypackage.dao.InvoiceDao">
> >>>        	<property name="hibernateTemplate">
> >>>        		<ref bean="hibernateTemplate"/>
> >>>        	</property>
> >>>        </bean>
> >>>......
> >>></beans>
> >>
> >>[...]
> >>
> >>Hello Andrew,
> >>
> >>remove the Home bean from your applicationContext
> >>and use
> >>
> >>@InjectObject("spring:InvoiceDao")
> >>public abstract InvoiceDao getInvoiceDao();
> >>
> >>instead. You need an additional jar:
> >>tapestry-spring.jar from 
> >>http://sourceforge.net/projects/diaphragma, look
> at 
> >>
> > 
> >
>
http://wiki.apache.org/jakarta-tapestry/Tapestry4Spring
> > 
> >>for more information.
> >>
> >>Oliver
> >>
> >>
> >>
> >>
> >>
> >>
> > 
> >
>
---------------------------------------------------------------------
> > 
> >>To unsubscribe, e-mail:
> >>tapestry-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail:
> >>tapestry-user-help@jakarta.apache.org
> >>
> >>
> > 
> > 
> > 
> > 
> > 	
> > 		
> > __________________________________ 
> > Yahoo! Mail - PC Magazine Editors' Choice 2005 
> > http://mail.yahoo.com
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> > 
> > 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 



		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

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


Re: Injecting Spring beans into page class

Posted by Ron Piterman <rp...@gmx.net>.
Tapestry Annotations are an *alternative* to the xml in the .page/.jwc, 
so you can do everything either with annotations or with xml -

in this case:

<inject object="spring:InvoiceDao" property="invoiceDAO"/>

and in your page class :

public abstract DAO getInvoiceDAO();


then use the abstract method normally,

Cheers,
Ron



ציטוט Andrew B:
> I have tapestry-spring.jar, and have read the wiki
> page. The last thing the wiki says is how to inject a
> Spring bean into the page, not the page class.
> 
> Is using the annotation
> @InjectObject("spring:InvoiceDao")
> the only way to do it? The reason I ask is that I am
> trying to avoid having to use JDK1.5 if possible, for
> compatiblity with deployment environments. But, if
> that's the only way to do the dependency injection,
> then that's what I'll have to do.
> 
> Thanks
> 
> 
> --- Oliver Lietz <ta...@oliverlietz.de> wrote:
> 
> 
>>Am Sonntag, 30. Oktober 2005 17:59 schrieb Andrew B:
>>
>>>Hi,
>>>
>>>I have a Tapestry 4/Spring/Hibernate application,
>>
>>and
>>
>>>I would like to inject a dependency into a page
>>
>>class,
>>
>>>that Tapestry then calls to render a page.
>>>
>>>The page class is Home, and the dependency is
>>>invoiceDao.  In my applicationContext I have:
>>>
>>><beans>
>>>        <bean id="Home"
>>
>>class="com.mypackage.Home">
>>
>>>        	<property name="invoiceDao">
>>>        		<ref bean="invoiceDao"/>
>>>        	</property>
>>>        </bean>
>>>
>>>        <bean id="invoiceDao"
>>>class="com.mypackage.dao.InvoiceDao">
>>>        	<property name="hibernateTemplate">
>>>        		<ref bean="hibernateTemplate"/>
>>>        	</property>
>>>        </bean>
>>>......
>>></beans>
>>
>>[...]
>>
>>Hello Andrew,
>>
>>remove the Home bean from your applicationContext
>>and use
>>
>>@InjectObject("spring:InvoiceDao")
>>public abstract InvoiceDao getInvoiceDao();
>>
>>instead. You need an additional jar:
>>tapestry-spring.jar from 
>>http://sourceforge.net/projects/diaphragma, look at 
>>
> 
> http://wiki.apache.org/jakarta-tapestry/Tapestry4Spring
> 
>>for more information.
>>
>>Oliver
>>
>>
>>
>>
>>
>>
> 
> ---------------------------------------------------------------------
> 
>>To unsubscribe, e-mail:
>>tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail:
>>tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


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


Re: Injecting Spring beans into page class

Posted by Robert Hannebauer <ro...@hannebauer.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

> Is using the annotation
> @InjectObject("spring:InvoiceDao")

it is possible to write some like
<inject property="foo" object="spring:bar" />
in your component description.

Robert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDZRhwu7yxnZcpRTYRAvaVAJ9Ulf7+uyxmt1v2t3xsfakV3s37JgCfSbYc
Lf1vHjv5ERYkZ5Gt9QnbayQ=
=Nrvv
-----END PGP SIGNATURE-----

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


Re: Injecting Spring beans into page class

Posted by Andrew B <ch...@yahoo.com>.
I have tapestry-spring.jar, and have read the wiki
page. The last thing the wiki says is how to inject a
Spring bean into the page, not the page class.

Is using the annotation
@InjectObject("spring:InvoiceDao")
the only way to do it? The reason I ask is that I am
trying to avoid having to use JDK1.5 if possible, for
compatiblity with deployment environments. But, if
that's the only way to do the dependency injection,
then that's what I'll have to do.

Thanks


--- Oliver Lietz <ta...@oliverlietz.de> wrote:

> Am Sonntag, 30. Oktober 2005 17:59 schrieb Andrew B:
> > Hi,
> >
> > I have a Tapestry 4/Spring/Hibernate application,
> and
> > I would like to inject a dependency into a page
> class,
> > that Tapestry then calls to render a page.
> >
> > The page class is Home, and the dependency is
> > invoiceDao.  In my applicationContext I have:
> >
> > <beans>
> >         <bean id="Home"
> class="com.mypackage.Home">
> >         	<property name="invoiceDao">
> >         		<ref bean="invoiceDao"/>
> >         	</property>
> >         </bean>
> >
> >         <bean id="invoiceDao"
> > class="com.mypackage.dao.InvoiceDao">
> >         	<property name="hibernateTemplate">
> >         		<ref bean="hibernateTemplate"/>
> >         	</property>
> >         </bean>
> > ......
> > </beans>
> [...]
> 
> Hello Andrew,
> 
> remove the Home bean from your applicationContext
> and use
> 
> @InjectObject("spring:InvoiceDao")
> public abstract InvoiceDao getInvoiceDao();
> 
> instead. You need an additional jar:
> tapestry-spring.jar from 
> http://sourceforge.net/projects/diaphragma, look at 
>
http://wiki.apache.org/jakarta-tapestry/Tapestry4Spring
> for more information.
> 
> Oliver
> 
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

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


Re: Injecting Spring beans into page class

Posted by Oliver Lietz <ta...@oliverlietz.de>.
Am Sonntag, 30. Oktober 2005 17:59 schrieb Andrew B:
> Hi,
>
> I have a Tapestry 4/Spring/Hibernate application, and
> I would like to inject a dependency into a page class,
> that Tapestry then calls to render a page.
>
> The page class is Home, and the dependency is
> invoiceDao.  In my applicationContext I have:
>
> <beans>
>         <bean id="Home" class="com.mypackage.Home">
>         	<property name="invoiceDao">
>         		<ref bean="invoiceDao"/>
>         	</property>
>         </bean>
>
>         <bean id="invoiceDao"
> class="com.mypackage.dao.InvoiceDao">
>         	<property name="hibernateTemplate">
>         		<ref bean="hibernateTemplate"/>
>         	</property>
>         </bean>
> ......
> </beans>
[...]

Hello Andrew,

remove the Home bean from your applicationContext and use

@InjectObject("spring:InvoiceDao")
public abstract InvoiceDao getInvoiceDao();

instead. You need an additional jar: tapestry-spring.jar from 
http://sourceforge.net/projects/diaphragma, look at 
http://wiki.apache.org/jakarta-tapestry/Tapestry4Spring for more information.

Oliver





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