On Nov 19, 6:08 pm, "John K." <[EMAIL PROTECTED]> wrote:
> ...
> All,
>
> What I'm trying to get at is, how do you rectify the two different
> objects. We all know now the solution I came up with but what
> strategy do you use?
>From your original use case, which is about forms, I create an object
for the form.
RegistrationForm extends (BaseForm extends AbstractForm).
The registration form has various steps that take a collection of user
input. It provides methods for checking if its valid, if the user
needs to complete a step because it has errors, or if the user can
move on.
I store the Form object in the session scope. I also use self posting
forms. Then when the form is submitted (http POST) I call the process
method of the form, pass in the values from the request, and ask the
form to validate. If it's valid we can process it and redirect, if
it's not we show the same view again usually so the user can fix the
form.
The form provides an error collection if it's not valid through a
getErrors() method that the view can call to show information.
If it's valid there's a method that creates the object (or objects)
the form represents, and returns them. In your use case we'd have a
createEmail() which creates and populates a brand new Email object
which we can then use for things.
// slight pseudo code:
function email( values ) {
var contactForm = session.contactForm;
var email = "";
if( cgi.request_method eq "post" ) {
contactForm.processStep1(values);
contactForm.validate();
if( not contactForm.hasAnyErrors() ) {
email = contactForm.createEmail();
getEmailService().send(email);
contactForm.clear();
renderView("contact/email-sent");
return;
}
// fall through and render the view anyway since we have
errors
}
renderView("contact/email-form");
}
Validation in Transfer objects is handled by a Validator object that
has a validate() method and validates against metadata and other
information from the database. Each object type has it's down
Validator object. The base Validator object has methods for creating
and manipulating error collections and custom validation routines.
So if we wanted an Email object to have a special Validator we could
just write one (instead of using runtime generated ones from the
database) and provide that to the Email object for validation.
Since something like a contact form is so basic, I think I'd probably
just only do the validation right in the Form object though.
Our form has a set of Required and Optional fields, and the validate()
method automatically makes sure those exist. We could then add custom
validation logic, like making sure the "email" field in the form
looked like an email.
The core platform code exists on RIAForge. The Form processing code is
very basic, but that's internal.
<http://svn.riaforge.org/saa/trunk/library/com/stellr/framework/
transfer/>
The general idea is just that your form is an Object too! Let it
validate itself and return errors to the view. If and when it's valid
you call some CreateFoo() method that returns the Foo object it has
the data to populate. We then call save(newObject);
If it's an update form them when it's valid call populateObject
(objectToUpdate) on it, and it'll add all it's values to the provided
object. We can then call save(objectToUpdate) on it.
Delete is similar, and so on.
Objects that could possible be "invalid" are honestly forms and stuff
that'd end up in Transfer (and therefore the database). Everything
beyond that "gap" is something the system would have validated already
and turned into a valid object by a Form (or similar object, ex. maybe
a CSVFileProcessor ).
(Sorry for the long post, trying to just throw out lots of concepts)
- Elliott
--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer
You received this message because you are subscribed to the Google Groups
"transfer-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---