I assume the getCheese method in your code below is declared public static to keep the example simple and to the point; you wouldn't normally expect to get your cheeses from a Page class. If you're comfortable with your page being coupled to the DAO interface (without, for instance, a service layer in between), you can just inject the DAO into your Component (Page) using http://cwiki.apache.org/WICKET/spring.html Wicket's @SpringBean annotation and have a private Cheese getCheese(String name) method that uses the DAO (refactor out your getting the name form a PageParameters into a separate method as well). Since you are following Wicket In Action, check out the sections on detachable models and layered architectures.
@SpringBean private ICheeseDao dao; Regards - Cemal http://www.jWeekend.co.uk http://jWeekend.co.uk quizzical wrote: > > Hi Everyone, > > I'm just getting started with wicket and am learning by playing around > with building an ecommerce application on top of wicket, spring and > hibernate. I've been (Ha!) using @SpringBean to inject my spring > dependencies and am very impressed with it. > > One thing I'm wondering about is how to use @SpringBean with a pattern in > the 'wicket in action' book. Specifically, when creating a > bookmarkablePageLink with pageparameters this pattern is used: > > public class CheeseDetailsPage extends WebPage { > // bookmarkable constructor > public CheeseDetailsPage(PageParameters parameters) { #1 > this(getCheese(parameters)); > } > // non-bookmarkable constructor > public CheeseDetailsPage(Cheese cheese) { #2 > // do cheesy stuff with the cheese > } > /** Retrieves a cheese object based on the ‘name’ parameter. */ > public static Cheese getCheese(PageParameters parameters) { #3 > String name = parameters.getString("name", ""); > if("".equals(name)) return null; > CheeseDao dao = ...; > return dao.getCheeseByName(name); > } > } > > I like this pattern but i'm having a problem with injecting my > dependencies. The getCheese() method is static, which means that the > CheeseDao would have to be static. I haven't delved into the code of the > @SpringBean proxy or the wicket serialization code (I have read the wiki > on @SpringBean) and I don't have an amazing understanding of proxies so > maybe i'm just being obtuse but heres my question. > > Is there any reason not to make the DAO static? > > Cheers in advance > > -- View this message in context: http://www.nabble.com/%40SpringBean-with-page-creation-patterns-tp20845794p20854319.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
