fernandospr (9) [Avatar] Offline
#1
Hi all,

I'm new to Wicket.
I'm building an application, actually finished most of the businness model classes.
My businness classes don't have a default constructor, they have a constructor with parameters. Inside the constructor, it calls to the setters. These have the business rules implemented.

For example:
public User(String email, String name,
String password, Date birth) throws BusinessException {
setEmail(email);
setName(name);
setPassword(password);
setBirth(birth);
}

public void setEmail(String email) throws BusinessException {
testSetEmail(email);
doSetEmail(email);
}

private void testSetEmail(String email) throws BusinessException {
// Check the format and if it is wrong throw a BusinessException
}

private void doSetEmail(String email) {
this.email = email;
}


Now, this is a trivial example, I have much more complex ones.
What I want to know is how should I use this kind of classes with Wicket.
I clearly cannot use the User object and a CompoundPropertyModel because I don't have a default constructor.
So, should I use a UserDTO and a CompoundPropertyModel and have the textfields in a form binded to it ? and then after the form is submitted obtain the properties from the DTO and create the real User object? Of course, I should try/catch the call to the constructor and if any exception is thrown show that to the user in a feedback panel.

What do you think?

Thanks.