I've started an application wit a lot of forms in with Wicket so I'm looking for how to write components well, reusable and mainly, easy to maintain.
Reading best practices from the guide it says to decouple more complex components (in the example a form with labels and panels) make it self-contained defining a method to create each form component:
public class BlogEditPage extends WebPage {
...
private Form<Blog> createBlogEditForm() {
Form<Blog> form = newBlogEditForm();
form.add(createHeadlineField());
form.add(createContentField());
form.add(createTagField());
form.add(createViewRightPanel());
form.add(createCommentRightPanel());
form.setOutputMarkupId(true);
return form;
}
// more methods here
}
At first it sounds weird to me, but considering each component can have it's own complexity, validation rules, it makes sense (this way it can be easily reused too).
But in the same section it also says to not create factories to components.. now it's weird cause the snippet above works like a factory to forms, and the page have factories to form components. Even the methods that creates form components being private, only form will can use it, and reusability is lost. So considering the second recommendation, these methods (that is implicit component factories) are not a good practice.
Any clarification of how to create complex components are welcome (with some code example will be better).
Thanks in advance.