runEvent versus setNextEvent

I have been reading the documentation and I am curious as to what are
the best practices for using setNextEvent and runEvent are. They
appear to be interchangeable and wasn't sure how the framework is
expecting them to be used.

thank you for you help

chris

setNextEvent is used to do a redirect at the end of a request, so you
current request will finish up and then do an http redirect (302 if I
recall) to the event you specify. runEvent executes another event in
the context of your current request, just invoking it but not
redirecting to it, so you have only 1 request total.

Example scenarios:

You have an edit form process that the form posts to. After you
validate the data and save it to the db, you would use setNextEvent to
redirect to, say, a listing page that shows the newly edited item
along with others in a list.

You are doing a bulk import of data from a file. You have one event
that knows how to import a single item, call it ImportItem and then
you have a higher level task called, perhaps, ImportAllItems.
ImportAllItems would know how to find the file, read it in and then
loop over it. For each iteration of the loop, you might call
RunEvent('foo.ImportItem') and pass it the data it needs for that one
item to import. After the loop is done, your request would finish
normally but you might have run the ImportItem event 10 times.

Does that clarify things?

Judah

so in this example -

I have a log in form, the form processes to a dologin method, running
a series of events using runEvent to setup a user struct in the cb
storage container, at the end of all the steps I want to send the user
to a search page, basically the default logged in page - if I used
setNextEvent it was taking forever, so, I switched to runEvent which
worked speedy as expected.

If I interpret your feedback correctly using runEvent in this scenario
would be accurate because the entire chain of events is considered one
event so runEvent should be used correct? If the user password combos
fail for any reason, I am using setNextEvent to send them back to the
log in page.

Based on your example am I viewing this correctly?

I use runEvent inside of my viewlets.

Regards,
Andrew Scott
http://www.andyscott.id.au/

If it was me in your doLogin event, I would be then doing a check from your
service/model then do something like this.

If(userService.doLogin()) {
  setView('failed login');
} else {
  setView('dashboard')
}

But yeah any time you might want to use another even to chain together,
runEvent is better.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of chris hough
Sent: Tuesday, 12 October 2010 7:06 AM
To: ColdBox Platform
Subject: [coldbox:6188] Re: runEvent versus setNextEvent

so in this example -

I have a log in form, the form processes to a dologin method, running a

series

of events using runEvent to setup a user struct in the cb storage

container, at

the end of all the steps I want to send the user to a search page,

basically the

default logged in page - if I used setNextEvent it was taking forever, so,

I

switched to runEvent which worked speedy as expected.

If I interpret your feedback correctly using runEvent in this scenario

would be

As for me I created an analogy for myself. runEvent is the same as and setNextEvent is the same as .