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 <fernando...@gmail.com>
To:     users@wicket.apache.org
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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org






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.

Reply via email to