Matt Feifarek wrote:
> Ian Bicking wrote:
>> I haven't been using actions very much up until now, but I used them
>> in the Wiki and found the method layout to be suboptimal. I think
>> other people have had the same experience.
> Yep. We've been grouchy about this for a couple of years. We made very
> similar changes to what you describe in our FormKit.
>> Second, _respond invokes writeHTML always, not just when no action was
> Yes, this is what should happen; UNLESS there's a redirect pending. Many
> times, after we do an action, we want to redirect to another URI. We do
> a check in writeHTML and bail if necessary, but I've always thought that
> it should be "deeper" in the servlet, perhaps in _respond() (or before;
> see next thought).
If you're using Page.sendRedirectAndEnd it won't be a problem -- that
immediately terminates the request. (I think it still calls sleep, but
> What do people think about making the action calls come from the awake()
> step rather than the respond() step? I think that respond is about
> sending data to the client; typically full of writeln() calls. Actions
> don't seem to be for that; they seem to be for writing to databases,
> parsing form input, setting state, etc. These things seem like they
> should come before "respond".
> Basically, what we'd like to see in the "new lifecycle" would be
> something like:
> 1. wake up (get connections to databases, open session, whatever)
> 2. do any business that's required (run a query, parse a file, whatever)
> 3. send output, which is either a redirect or content
> 4. go to sleep (close connections, etc.)
> We always do step 2 things in actions, but have always thought that they
> shouldn't be jacked into this "pre-respond" place.
With the technique I describe it's really a 4 step cycle -- run awake,
run the action (always some action, if only defaultAction), run
writeHTML, run sleep. Technically the action and writeHTML happen in
respond, but you only see the respond method when you are looking at it
from WebKit's perspective. An an application author I never override
that, so it's not a problem.
Where you write output is really a matter of convention -- you can do it
anywhere, even in sleep.
I like the idea of the action and awake being separate, where awake is a
kind of general setup and action is specific. You'll still want the
general setup, because presumably there's something that ties all the
actions together into a single servlet. So I think four steps are
called for. If this gets added to awake, it would be awkward, because
Page.awake would invoke your actions before you had a chance to do your
Also note, though, that the awake/respond/sleep sequence is less hard
coded (in CVS) than it was before -- you can override all three with
runTransaction. So another completely separate method could be added to
that sequence. But I also don't think it's so bad to add it to respond,
so long as it happens before writeHTML (but not in lieu of writeHTML).