Hi all,

I'm migrating a spring-mvc project to wicket. In this project domain objects
are directly exposed to the ui (without DTOs in between). The objects are
validated using the spring bean validation framework (part of
springmodules). This module creates a unique Validator (a spring interface)
from annotations given in the fields/properties of every validatable object.
Then you inject this global validator to your controllers (in the case of
spring-mvc) so they can validate their form/command (the bound object). The
result of validation is an Errors objects, with field errors and global
errors (more precisely, error codes to be resolved against a messages
resource). It's pretty easy to map these errors from bean properties to
wicket component ids. This should be done inside onSubmit(), once the object
is bound (for example, using a CompoundPropertyModel). So, to recap: domain
objects directly exposed to the ui, Validator created from annotations in
validatable domain objects, domain objects bound by PropertyModels, domain
objects validated by injected validator during onSubmit. Up to this point
I'm pretty happy with the results, validation is almost trivial with the
annotations and the valang dsl, and I like it being inside the domain
instead of tied to the ui components.

One problem I have due to avoiding DTOs is that most of the time I don't
want to serialize my form models, because they are (often big) entities with
lazy loaded associations. So in principle I would use an
LoadableDetachableModel to load the entity from the repository each time the
model is reattached. But suppose I'm updating a UserProfile. The first time
it would be ok to populate the model from the persistent profile to be
updated. But once the form is submitted there's no point in loading the
profile from the repository again because its properties would be
overwritten from those coming from the form anyway. So I'm tempted to
subclass AbstractDetachableModel so that it loads the profile from the
repository upon creation, but instantiates a brand new profile to be
populated from the form upon reattachment. Is there a better pattern for
this? Anyone has run into the same problem?

Cheers,
Carlos
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to