I would recommend using a custom model for this.  The advantage is that it
can be used anywhere. Something like:

   // bookmarkable constructor
   public CheeseDetailsPage(PageParameters parameters) {   #1
       this(new CheeseByIDModel(getIDFromParams(parameters)));
   }
   // non-bookmarkable constructor
   public CheeseDetailsPage(IModel<Cheese> cheese) {         #2
       // do cheesy stuff with the cheese
   }
   private statuc int getIDFromParams(PageParameters params) {
      return params.getInteger("foo");
   }

Even better would be to do something very reusable like:
new DomainEntityModel<Cheese>(Cheese.class, getIDFromParameters(parameters))

See http://wicketinaction.com/2008/09/building-a-smart-entitymodel/ for some
ideas about this.



On Thu, Dec 4, 2008 at 6:50 PM, quizzical <[EMAIL PROTECTED]> 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-tp20845794p20845794.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]
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com

Reply via email to