If the fields (user/pwd) always go together on every pages, why not having having one root Panel (called MyPanel) knowing the fields , validation etc and several Panels that simply extends MyPanel ; avec each child has its own layouts.
Best regards, Gabriel Kastenbaum http://blog.oxiane.com 2009/5/8 Martin Makundi <[email protected]> > > TextField t = new ValidatedTextField("id", new Model("your > Model"), > > And remember to use Model.of("your Model") > > ** > Martin > http://tyoajanseuranta.blogit.fi/ Wicket työajanseuranta > > > true, > > EmailAddressValidator.getInstance(), > > StringValidator.maximumLength(50)); > > </code> > > > > Maybe you could then use it in a class factory as you suggested. At least > it > > will shorten a few lines of code. > > Best regards. > > -- > > Marc Nuri > > http://blog.marcnuri.com > > On Fri, May 8, 2009 at 11:14 AM, Christian Helmbold < > > [email protected]> wrote: > > > >> > >> I think the difference between sub classing and static factory methods > is a > >> matter of taste in this case. > >> > >> If I have many fields, I'd need many classes for them. So I'd group them > in > >> a sub package. In the case of factory methods I'd group the methods to > >> create fields in a class instead of a package. > >> > >> Subclass: > >> > >> 1 class UserEmailField extends TextField { > >> 2 public UserEmailField(String id, IModel model) { > >> 3 super(id, model); > >> 4 setRequired(true); > >> 5 add(EmailAddressValidator.getInstance()) > >> 6 add(UniqueValidator.unique(SystemUser.class, "email")); > >> 7 } > >> 8 } > >> > >> Factory method: > >> > >> 1 public static TextField emailTextField(String id){ > >> 2 return (TextField) new TextField(id) > >> 3 .setRequired(true) > >> 4 .add(EmailAddressValidator.getInstance()) > >> 5 .add(UniqueValidator.unique(SystemUser.class, > >> "email")); > >> 6 } > >> > >> Your answer shows me, that there is no dramatically simpler way to do > this. > >> If you ignore the two lines for factory class declaration factory > methods > >> are even a bit shorter. Or is there an advantage of sub classing that I > have > >> missed? > >> > >> Regards, > >> Christian > >> > >> > >> > >> ----- Ursprüngliche Mail ---- > >> > Von: Igor Vaynberg <[email protected]> > >> > An: [email protected] > >> > Gesendet: Freitag, den 8. Mai 2009, 09:08:34 Uhr > >> > Betreff: Re: How to avoid code duplication on forms? > >> > > >> > much simpler > >> > > >> > class UserEmailField extends TextField { > >> > public UserEmailField(String id, IModel model) { > >> > super(id, model); > >> > add(EmailAddressValidator.getInstance()) > >> > add(UniqueValidator.unique(SystemUser.class, "email")); > >> > } > >> > } > >> > >> > >> > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [email protected] > >> For additional commands, e-mail: [email protected] > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
