If the form submission was a lot more complex and required the saving of,
say, 10 different objects. Would you still interact with each object
individually in the controller, or move all of that to a service function
that orchestrates the interactions? If you would choose the latter, and
given that in the another post you said that you would handle the creation
of objects in the service rather than the controller, you are then faced
with the issue of how to return the bean(s) and/or errorcollection from the
save() method...
You know?
Baz
On Jan 13, 2008 5:15 PM, Baz <[EMAIL PROTECTED]> wrote:
> Hey Peter,
>
> Looks very tidy! So I guess the validation occurs in the save() method.
> What would that method return, True/False? And then later on you would
> evaluate the result to see whether to retrieve the error collection?
>
> Cheers,
> Baz
>
>
> On Jan 13, 2008 5:08 PM, Peter Bell <[EMAIL PROTECTED]> wrote:
>
> > Hi Baz,
> >
> > Why not just:
> >
> > var Result = ";
> > var User = UserService.new(User);
> > User.LoadStruct(form);
> > Result = User.save();
> > AddResult(Result);
> >
> > I have some generic code so I don't have to type this for every
> > controller that handles a form, but this is generally what I do.
> >
> > Best Wishes,
> > Peter
> >
> >
> >
> > On 1/13/08 8:00 PM, "Baz" <[EMAIL PROTECTED]> wrote:
> >
> > Another design choice I see go both ways is whether to perform
> > validation in the save() method or to call each method separately. Example
> > controller functions could be (pseudo code):
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > - - - - - - - - -
> >
> > *SEPARATE SAVE & VALIDATE
> > *var UserService=getBean('UserService');
> > var FormVariables=getAllValues();
> >
> > var ValidationResult='';
> > var SaveResult='';
> >
> > set ValidationResult=UserService.validate(FormVariables); // returns an
> > error collection object
> >
> > if ValidationResult.hasErrors()
> > setValue('ReturnObject', ValidationResult);
> > addResult('Fail');
> > else
> > set SaveResult=UserService.save (FormVariables); // returns a
> > populated user bean object
> > setValue('ReturnObject', SaveResult);
> > addResult('Success');
> > end
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > - - - - - - - - -
> >
> > *COMBINED SAVE & VALIDATE V1.0
> > *var UserService=getBean('UserService');
> > var FormVariables=getAllValues();
> >
> > var UserBean=UserService.newUser();
> > var SaveResult='';
> >
> > set UserBean.setMemento(FormValues);
> > set SaveResult=UserService.save(UserBean); // returns true if saved
> > successfully, or false if validation errors exist (the error collection
> > would be saved in the bean itself for retrieval later)
> >
> > setValue('ReturnObject', UserBean);
> >
> > if SaveResult is True
> > addResult('Success');
> > else
> > addResult('Fail');
> > end
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > - - - - - - - - -
> >
> > *COMBINED SAVE & VALIDATE V2.0
> > *var UserService=getBean('UserService');
> > var FormVariables=getAllValues();
> >
> > var SaveResult=UserService.save(FormVariables); // returns a complex
> > result object with properties: STATUS ('Success', ValidationError') and
> > PAYLOAD (that contains either a UserBean or ErrorCollection depending on the
> > STATUS)
> >
> > setValue('ReturnObject ', SaveResult.getPayload() );
> >
> > if SaveResult.getStatus() is 'Success'
> > addResult('Success');
> >
> > else SaveResult.getStatus() is 'Validation'
> > addResult('Fail');
> > end
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > - - - - - - - - -
> >
> > CONS OF KEEPING THEM SEPARATE:
> >
> > - Controller has to be smarter, which is bad, because there will
> > be more code duplication if you change the presentation layer to flex,
> > for
> > example.
> > - Function coupling: Coders have to "remember" to always
> > validate() before saving() - an unnecessary additional complexity
> > (unless,
> > of course, there are times in your app where you save() by defining all
> > values yourself (thereby knowing the values are correct) rather than from
> > user input)
> >
> > CONS OF COMBINING THEM COMBINED
> >
> > - Requires complex and unnatural result handling (either by
> > affecting the bean by reference, or using a special RESULT object)
> >
> >
> > Cheers,
> > Baz
> >
> >
> >
> >
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" 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/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---