Ok but if the conversion has to be done multiple times why not encapsulate it and clean up your code, rather than coding a conversion for each dto every time its needed. With my suggestion the frontend calls a service to do the conversion, then supplies the "primed" object to the service to persist it. I somewhat agree the service perhaps should not need to know about the frontend's model to do its task.
Never the less its probably a matter of taste... Back to the original question...what if you extract your business object validation out into a service. Then your business objects can call that service to validate, and you can write custom validators for wicket that call the same validation service. This would prevent you from having to write validations twice in both the business layer and frontend and gives you the ability to attach an error at the component level, no? From: James Carman <[email protected]> To: [email protected] Date: 01/28/2011 04:46 PM Subject: Re: Using Wicket with businness model classes that check for rules Sent by: [email protected] I don't know that I would agree that the conversion logic needs to be taken out of the front end. The front end is where the data is collected. It may have to be collected in a specific way (FileUploadField perhaps) that is connected with the chosen presentation layer (Wicket in our case). It is the UI's responsibility to translate the input it receives from its user(s) and transform it into a format that the "business model" requires. That's my $0.02 On Fri, Jan 28, 2011 at 4:19 PM, <[email protected]> wrote: > Right right right, good catch, but I suppose you could write a conversion > service which throws the business exception. Not really a solution to > your question, but it would clean up your code a bit and take conversion > logic out of the frontend. > > > > From: James Carman <[email protected]> > To: [email protected] > Date: 01/28/2011 04:13 PM > Subject: Re: Using Wicket with businness model classes that check > for rules > Sent by: [email protected] > > > > But, then you lose the component-specific error messages. > > On Fri, Jan 28, 2011 at 4:08 PM, <[email protected]> wrote: >> Just a suggestion, pass the UserDto to the service layer and let the >> service layer do the conversion. Then you can look at <a href=" >> http://code.google.com/p/simple-object-assembler/">Simple Object >> Assembler</a> to encapsulate the conversion. Hint: use >> automapWhenNoConverterFound property and you won't need to write any >> converters for Simple Object Assembler (assuming your properties follow > a >> naming convention). >> >> >> >> >> From: fernandospr <[email protected]> >> To: [email protected] >> Date: 01/28/2011 04:00 PM >> Subject: Re: Using Wicket with businness model classes that check >> for rules >> >> >> >> >> Thanks James I'll investigate on extending PropertyModel. >> >> Currently I'm doing the following: >> >> public class UserRegistrationPage extends WebPage { >> @SpringBean >> private UserService userService; >> >> private FeedbackPanel feedbackPanel; >> private UserDto userDto; // only has the User properties >> >> @SuppressWarnings("unchecked") >> public UserRegistrationPage() { >> feedbackPanel = new >> FeedbackPanel("feedback"); >> userDto = new UserDto(); >> CompoundPropertyModel userDtoModel = new >> CompoundPropertyModel(userDto); >> // bind to the DTO >> >> Form registrarForm = new >> Form("registerForm", userDtoModel){ >> @Override >> protected void > onSubmit() >> { >> try { >> // Create a real User and obtain >> the >> data from the DTO >> User user = new User(userDto.getEmail(), >> userDto.getName(), >> userDto.getPassword(), >> userDto.getBirth()); >> userService.save(user); // service calls the dao which actually saves >> to DB >> } catch >> (Exception e) { // The Businness Exception has the message error >> feedbackPanel.warn(e.getMessage()); >> } >> } >> }; >> >> registerForm.add(new >> TextField("email").setRequired(true)); // form binded >> to the DTO properties >> ... >> -- >> View this message in context: >> > http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3245378.html > >> >> Sent from the Users forum mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >> >> >> >> >> Notice: This communication, including any attachments, is intended > solely >> for the use of the individual or entity to which it is addressed. This >> communication may contain information that is protected from disclosure >> under State and/or Federal law. Please notify the sender immediately if >> you have received this communication in error and delete this email from >> your system. If you are not the intended recipient, you are requested > not >> to disclose, copy, distribute or take any action in reliance on the >> contents of this information. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > > > > Notice: This communication, including any attachments, is intended solely > for the use of the individual or entity to which it is addressed. This > communication may contain information that is protected from disclosure > under State and/or Federal law. Please notify the sender immediately if > you have received this communication in error and delete this email from > your system. If you are not the intended recipient, you are requested not > to disclose, copy, distribute or take any action in reliance on the > contents of this information. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] Notice: This communication, including any attachments, is intended solely for the use of the individual or entity to which it is addressed. This communication may contain information that is protected from disclosure under State and/or Federal law. Please notify the sender immediately if you have received this communication in error and delete this email from your system. If you are not the intended recipient, you are requested not to disclose, copy, distribute or take any action in reliance on the contents of this information.
