Nice. It is a good idea to work with detachable models, especially when
working with lazy collections etc. But SpringBeanModel seems to do that.
Having a quick look at the code, it could be improved a bit, I attached
the patch. However, I don't currently use any Spring classes, so I don't
know if there's any potential problems with it.
If you have any improvements, please let us know!
Eelco
Dan Gould wrote:
Thanks Martijn.
[I actually am going to go the Spring route (since I set up it before
getting your email).
I've got Spring configured with wicket-contrib-spring and I can get the
simple beans in the example. I just configured Hibernate, wrote my DAOs
and Managers. Next I need to figure out how to actually use them with
Wicket Models; I'm still a bit confused about how to use
wicket.contrib.spring.SpringBeanModel (or whatever's appropriate) with
my objects and the DAOs, but I'm making progress.
Hopefull I'll have an example config for the Wiki when this is done...]
Thanks again,
Dan
-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
Index: SpringBeanModel.java
===================================================================
RCS file:
/cvsroot/wicket-stuff/wicket-contrib-spring/src/java/wicket/contrib/spring/SpringBeanModel.java,v
retrieving revision 1.3
diff -u -r1.3 SpringBeanModel.java
--- SpringBeanModel.java 30 Apr 2005 21:21:24 -0000 1.3
+++ SpringBeanModel.java 17 May 2005 10:32:46 -0000
@@ -27,8 +27,8 @@
import wicket.RequestCycle;
import wicket.WicketRuntimeException;
import wicket.model.AbstractDetachableModel;
-import wicket.model.AbstractModel;
import wicket.model.IModel;
+import wicket.model.LoadableDetachableModel;
/**
* Base class for transparent access of Spring managed beans. It can be used in
@@ -121,27 +121,14 @@
throw new IllegalArgumentException("beanName must not be null");
}
- this.model = new AbstractModel()
+ this.model = new LoadableDetachableModel()
{
- private Object object = null;
-
- public Object getObject(final Component component)
- {
- if (object == null)
- {
- object = getApplicationContext().getBean(beanName);
- }
- return object;
- }
-
- public void setObject(final Component component, final Object
object)
- {
- this.object = object;
- }
-
- public IModel getNestedModel()
+ /**
+ * @see wicket.model.LoadableDetachableModel#load()
+ */
+ protected Object load()
{
- return null;
+ return
getApplicationContext().getBean(beanName);
}
};
}
@@ -183,6 +170,9 @@
this.applicationContext =
SpringContextLocator.getApplicationContext(RequestCycle.get());
}
+ /**
+ * @see wicket.model.AbstractDetachableModel#onDetach()
+ */
protected void onDetach()
{
this.applicationContext = null;