Hello,

Wicket uses input validation on the presentation layer. This leads often to 
code duplication and I'm looking for a way to avoid it.

Example: I have a registration form where you fill in your first and last name, 
password and so on. Every field has its restrictions like max length or 
required. Registered users have a form for their personal information with 
additional fields. The password can be changed on a seperate page.

How can I avoid to double the programmtic configuration of the form fields? To 
extract and reuse panels is not an option, because of the different composition 
of the forms. 

a) I could create a subclass for every form field, but this would be a lot of 
writing.

b)I could create something like a FormFieldFactory:

public class UserFormFieldFactory
{
    public static TextField createEmailField()
    {
        return new TextField("email")
            .setRequired(true)
            .add(EmailAddressValidator.getInstance())
            .add(UniqueValidator.unique(SystemUser.class, "email"));
    }
    
    public static PasswordTextField createPasswordField()
    {
        ...
    }
    ...
}

c) ?

How do you avoid code duplication on forms?

Regards,
Christian




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to