http://www.wicket-wiki.org.uk/wiki/index.php/Spring
I only had time for one pass, so its prob got some mistakes in it, feel free to add/fix/cleanup whatever you think it needs.
I am also attaching a patch for the wicket-phonebook project which takes advantage of the new wicket-contrib-spring lazy init proxies.
-Igor
On 11/14/05, Phil Kulak <[EMAIL PROTECTED]> wrote:
It's best to keep your app context beans in the Wicket application.
See the wicket-phonebook example in wicket-stuff cvs.
On 11/14/05, Maik Dobryn <[EMAIL PROTECTED]> wrote:
> Hi Igor,
>
> I'm very new to Wicket. The last days I tried to figure out how the
> Spring integration in Wicket works.
>
> There is a lot of confusion about the most recent practice.
> Unforturnatly, no documentation does exist which covers this important
> technique.
>
> So would You please provide a small (code) example of setting up a
> Spring application context and injecting a bean at page level?
>
> Thank You in advance,
>
> Maik
>
>
> on 2005-11-11 00:50 Igor Vaynberg wrote:
> >more refactoring/tests and some new things:
> >
> >SpringWebApplicationFactory - which will pull the webapplication
> >subclass out of spring application context
> >
> >SpringInjector/SpringWebApplica tion - make it very simple to inject
> >objects using @SpringBean annotation with lazy-init proxies
> >
> >SpringWebPage - autoinitailizes its subclasses using the SpringInjector
> >
> >I also deprecated all the old stuff and moved it into
> >wicket.contrib.spring.old package. The new stuff is the
> >"official/supported/standard/whateveryouwanttocallit" way to do spring
> >integration.
> >
> >currently we only provide an easy way to inject objects using jdk5
> >annotations. it is possible to create a jdk1.4 object locator
> >factories, but there are many options as to how to store metadata/do
> >the lookup. if someone is interested in this please let me know and we
> >can discuss some ways of doing this.
> >
> >As always, any feedback is greatly appreciated.
> >
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
> Register for a JBoss Training Course. Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_idv28&alloc_id845&opclick
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
Index: src/webapp/WEB-INF/web.xml
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-phonebook/src/webapp/WEB-INF/web.xml,v
retrieving revision 1.1
diff -u -r1.1 web.xml
--- src/webapp/WEB-INF/web.xml 8 Oct 2005 07:16:47 -0000 1.1
+++ src/webapp/WEB-INF/web.xml 15 Nov 2005 01:15:58 -0000
@@ -32,7 +32,7 @@
<servlet-class>wicket.protocol.http.WicketServlet</servlet-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
-
<param-value>wicket.contrib.phonebook.web.SpringApplicationFactory</param-value>
+
<param-value>wicket.contrib.spring.SpringWebApplicationFactory</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Index: src/java/wicket/contrib/phonebook/web/page/BasePage.java
===================================================================
RCS file:
/cvsroot/wicket-stuff/wicket-phonebook/src/java/wicket/contrib/phonebook/web/page/BasePage.java,v
retrieving revision 1.2
diff -u -r1.2 BasePage.java
--- src/java/wicket/contrib/phonebook/web/page/BasePage.java 13 Oct 2005
08:21:29 -0000 1.2
+++ src/java/wicket/contrib/phonebook/web/page/BasePage.java 15 Nov 2005
01:15:58 -0000
@@ -19,21 +19,33 @@
package wicket.contrib.phonebook.web.page;
import wicket.contrib.phonebook.ContactDao;
-import wicket.contrib.phonebook.web.PhonebookApplication;
+import wicket.contrib.spring.SpringWebPage;
+import wicket.contrib.spring.injection.SpringBean;
import wicket.markup.html.WebPage;
/**
* Extends [EMAIL PROTECTED] WebPage} in order to provide the [EMAIL
PROTECTED] #getContactDao}
* method.
- *
+ *
* @author igor
*/
-public class BasePage extends WebPage {
+public class BasePage extends SpringWebPage {
+
+ /**
+ * Here we specify that contactDao is a bean we wish to retrieve from
+ * spring. We need to specify the name attribute because the context
+ * contains two beans with ContactDao interface - the dao and the
+ * transactional proxy.
+ */
+ @SpringBean(name = "contactDao")
+ private ContactDao contactDao;
+
/**
* Gets the Contact DAO instance.
+ *
* @return The Contact DAO instance.
*/
protected ContactDao getContactDao() {
- return PhonebookApplication.getInstance().getContactDao();
+ return contactDao;
}
}
Index: src/java/wicket/contrib/phonebook/web/PhonebookApplication.java
===================================================================
RCS file:
/cvsroot/wicket-stuff/wicket-phonebook/src/java/wicket/contrib/phonebook/web/PhonebookApplication.java,v
retrieving revision 1.2
diff -u -r1.2 PhonebookApplication.java
--- src/java/wicket/contrib/phonebook/web/PhonebookApplication.java 13 Oct
2005 08:21:29 -0000 1.2
+++ src/java/wicket/contrib/phonebook/web/PhonebookApplication.java 15 Nov
2005 01:15:58 -0000
@@ -20,6 +20,7 @@
import wicket.contrib.phonebook.ContactDao;
import wicket.contrib.phonebook.web.page.ListContactsPage;
+import wicket.contrib.spring.SpringWebApplication;
import wicket.protocol.http.WebApplication;
/**
@@ -27,7 +28,7 @@
* @author igor
*
*/
-public class PhonebookApplication extends WebApplication {
+public class PhonebookApplication extends SpringWebApplication {
private ContactDao contactDao;
