Re: Using Wicket with businness model classes that check for rules
Thank you all for the responses ! And if you have more ideas let me know ! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3246809.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
Re: Using Wicket with businness model classes that check for rules
Another way to handle this is to leverage the wicket validation process by extending FormComponentPanel. Your userEditPanel would be composed of individual textfields whose models are not linked to your IModel. Then implement the convertInput method that builds a new User object from the validated field values when the form is submitted. For example: public class UserEditPanel extends FormComponentPanel { private TextFieldemailField; /** * @param id */ public UserEditPanel(String id, IModeluserModel) { super(id, userModel); emailField = new TextField("emailField", new Model("")); emailField.add(new EmailValidator()); } @Override protected void convertInput() { /** * Build up a new User instance from the values in the fields. * */ User u = new User(emailField.getModelObject(), ...); setConvertedInput(u); } /* * Here we pull out each field from the User if it exists and put the contents into the fields. */ @Override protected void onBeforeRender() { User u = this.getModelObject(); if (u != null) { // copy the field values into the form fields. this.emailField.setModelObject(u.getEmailAddress()); } } } I only implemented for one field but you can see that if you refactored the User.testSetEmail() into a static utility class then you could use it inside the EmailValidator(). This would allow you to show errors as required to ensure the fields of the User object were entered in correctly. Further you can add Validators directly to the UserEditPanel that can be used to validate the built User object. I find this useful especially for cases like you describe with multiple layers of IModel's; it allows the complexity to be internalized and then users of the panel don't need to care about the internals only that when it validates properly you call .getModelObject() and get the valid User object back. e.g. UserEditPanel userEditPanel = new UserEditPanel ("userPanel", new Model()); add (form = new Form("form") { @Override protected void onSubmit() { // this is only called if there are no validation errors in the form fields // the validation logic built into the UserEditPanel is implicity used and will prevent this method from being called // if an error is detected. User u = userEditPanel.getModelObject(); userService.save(u); } }); form.add (userEditPanel); Regards, Mike 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 ... - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Using Wicket with businness model classes that check for rules
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 To: users@wicket.apache.org Date: 01/28/2011 04:46 PM Subject: Re: Using Wicket with businness model classes that check for rules Sent by:jcar...@carmanconsulting.com 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, 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 > To: users@wicket.apache.org > Date: 01/28/2011 04:13 PM > Subject: Re: Using Wicket with businness model classes that check > for rules > Sent by:jcar...@carmanconsulting.com > > > > But, then you lose the component-specific error messages. > > On Fri, Jan 28, 2011 at 4:08 PM, wrote: >> Just a suggestion, pass the UserDto to the service layer and let the >> service layer do the conversion. Then you can look at http://code.google.com/p/simple-object-assembler/";>Simple Object >> Assembler 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 >> 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()); >> }
Re: Using Wicket with businness model classes that check for rules
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, 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 > To: users@wicket.apache.org > Date: 01/28/2011 04:13 PM > Subject: Re: Using Wicket with businness model classes that check > for rules > Sent by: jcar...@carmanconsulting.com > > > > But, then you lose the component-specific error messages. > > On Fri, Jan 28, 2011 at 4:08 PM, wrote: >> Just a suggestion, pass the UserDto to the service layer and let the >> service layer do the conversion. Then you can look at http://code.google.com/p/simple-object-assembler/";>Simple Object >> Assembler 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 >> 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 >>
Re: Using Wicket with businness model classes that check for rules
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 To: users@wicket.apache.org Date: 01/28/2011 04:13 PM Subject:Re: Using Wicket with businness model classes that check for rules Sent by:jcar...@carmanconsulting.com But, then you lose the component-specific error messages. On Fri, Jan 28, 2011 at 4:08 PM, wrote: > Just a suggestion, pass the UserDto to the service layer and let the > service layer do the conversion. Then you can look at http://code.google.com/p/simple-object-assembler/";>Simple Object > Assembler 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 > 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. - 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.
Re: Using Wicket with businness model classes that check for rules
The problem with that approach is that you don't get all of the errors at once. The user would have to submit, see an error, fix, resubmit, see another error, etc. On Fri, Jan 28, 2011 at 3:59 PM, fernandospr wrote: > > 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 > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Using Wicket with businness model classes that check for rules
But, then you lose the component-specific error messages. On Fri, Jan 28, 2011 at 4:08 PM, wrote: > Just a suggestion, pass the UserDto to the service layer and let the > service layer do the conversion. Then you can look at http://code.google.com/p/simple-object-assembler/";>Simple Object > Assembler 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 > 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. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Using Wicket with businness model classes that check for rules
Just a suggestion, pass the UserDto to the service layer and let the service layer do the conversion. Then you can look at http://code.google.com/p/simple-object-assembler/";>Simple Object Assembler 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 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.
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
Re: Using Wicket with businness model classes that check for rules
Well, you could create your own BusinessPropertyModel class that subclasses PropertyModel and catches those exceptions, perhaps. You'd have to figure out an elegant way to propagate the error message to the FormComponent that caused the issue. If you don't need component-specific error messages you could just call error() on the Session, I guess. On Fri, Jan 28, 2011 at 3:34 PM, fernandospr wrote: > > Thanks James that was a quick response. > The problem is that I already have many classes designed this way. > Also, the classes where created on purpose this way as an analysis/design > decision, I mean, only valid business objects should be created. > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3245323.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 > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Using Wicket with businness model classes that check for rules
Thanks James that was a quick response. The problem is that I already have many classes designed this way. Also, the classes where created on purpose this way as an analysis/design decision, I mean, only valid business objects should be created. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3245323.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
Re: Using Wicket with businness model classes that check for rules
What about having a Validatable interface instead? I realize that this would allow you to put your business objects into an invalid state, but it would help make things easier :) On Fri, Jan 28, 2011 at 3:18 PM, fernandospr wrote: > > 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. > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3245298.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 > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Using Wicket with businness model classes that check for rules
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. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-Wicket-with-businness-model-classes-that-check-for-rules-tp3245298p3245298.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