On Jan 13, 2008 7: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?
>
>
>


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

Like Peter, I have generic code to take care of this, but for the reasons
you listed (Baz) under why it's bad to keep the separate, I like to keep
them in one function (well, validate() /can/ be called publicly, but it is
also called when you call save().)

save returns a list of errors, or blank if no errors existed.  I don't like
the name for that purpose, but it is mighty useful to not have to recall
what order which operations need to be performed from the outside.

Of course, it's all automated for me so it's not like I'd need to change it
often.  But it's nice for those times when I need to break the normal cycle.

Sam

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

Reply via email to