Jim,

Here's a quickie example of how I personally handle such things.

// modelglue.xml
<event-handler name="do.register">
    <broadcasts>
        <message name="handleRegisterUser" />
    </broadcasts>
    <results>
        <result name="RegistrationSuccess" do="register.done"
redirect="true" />
        <result name="RegistrationFailure" do="register" redirect="true" />
    </results>
    <views />
</event-handler>

// controller method
public void function doRegisterUser (
            required any Event
        )
{
    var user = beans.UserService.createUser(args=event.getAllValues());
    if ( user.getIsPersisted() )
    {
        event.addResult("RegistrationSuccess");
    }
    else
    {
        event.setValue("user",user);
        event.addResult("RegistrationFailure");
    }
}

// service method
public any function createUser (
            required struct args
        )
{
    var user = entityNew("User");
    user.populate(arguments.args);
    if ( user.validate(context="new") )
    {
        entitySave(user);
    }
    return user;
}

Hopefully most of that is all simple enough to make sense as to what is
going on.  If you have questions, certainly ask.

I will, however, expand slightly on two points...

1) The validation routine there in the service method.  I inject VT into the
object, and so the call to user.validate() internally passes the handling of
the task on to VT.

2) The controller method checks user.getIsPersisted() to determine whether
to add a success or failure result.  This method internally checks the ID.
If it is not NULL or 0, it is considered persisted. (There's no other way
for it to get a different ID.)

Now then, in the MG XML I am doing a redirect.  MG will persist the 'user'
across the redirect request.  Yes, since I am using CF9 ORM/Hibernate, this
creates a detached object.  But I am not doing any kind of relationship
manipulation with it, so it's all good.  On the form (I am using cfUniForm,
naturally), I simply pass the errors from the user object in, and voila.

HTH

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" 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/model-glue?hl=en

Reply via email to