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
-~----------~----~----~----~------~----~------~--~---