Discussion:
[jifty-devel] Continuations and Actions
Mikko Lipasti
2008-03-26 14:33:44 UTC
Permalink
Hello list,

Let 'search' be a page with a SearchThing action, a form for it and a section which prints out search results. Each search result has a tangent link to 'detail' page about that "thing". 'detail' page has a "return" link.

When I click return, 'search' page is loaded but SearchAction has lost its args, which is kind of counter-intuitive, assuming I'm not completely in mistaken about the purpose of continuations.

Is there a way to make this work the way I want it to?

- Mikko
Alex Vandiver
2008-03-26 15:15:28 UTC
Permalink
Post by Mikko Lipasti
Let 'search' be a page with a SearchThing action, a form for it and a
section which prints out search results. Each search result has a
tangent link to 'detail' page about that "thing". 'detail' page has a
"return" link.
When I click return, 'search' page is loaded but SearchAction has lost
its args, which is kind of counter-intuitive, assuming I'm not
completely in mistaken about the purpose of continuations.
You're not mistaken about the purpose, merely the implementation. Jifty
doesn't make continuations for every page, only when a user clicks on a
link. Here's what Jifty is doing right now:

1. 'search' page with results
2. -> click link
3. 'search' page is reloaded (probably without results)
4. -> continuation saved
5. -> redirected to 'detail' page
6. 'detail' page is shown
7. -> click link
8. -> continuation loaded
9. -> redirected to 'search' page (probably without results)
10. 'search' page without results

The difficulty is that you're expecting the steps to happen in the
order:

1. 'search' page with results
4. -> continuation saved
2. -> click link
5. -> redirected to 'detail' page
6. 'detail' page is shown
7. -> click link
8. -> continuation loaded
9. -> redirected to 'search' page
10. 'search' page

This is what, for example, Seaside would do. Jifty doesn't do this by
default because it would mean continuations would pile up, one for every
page. You *can* do this if you want, but the way we generally suggest
is rather:

1. 'search' page with results
2. -> click link
2.5. -> also submit the search action with the link
3. 'search' page is reloaded (with results of action)
4. -> continuation saved
5. -> redirected to 'detail' page
6. 'detail' page is shown
7. -> click link
8. -> continuation loaded
9. -> redirected to 'search' page (with results of action)
10. 'search' page

Does that make sense?
- Alex
Mikko Lipasti
2008-03-27 11:15:46 UTC
Permalink
Post by Alex Vandiver
This is what, for example, Seaside would do. Jifty doesn't do this
by default because it would mean continuations would pile up, one for
every page. You *can* do this if you want, but the way we generally
1. 'search' page with results
2. -> click link
2.5. -> also submit the search action with the link
3. 'search' page is reloaded (with results of action)
4. -> continuation saved
5. -> redirected to 'detail' page
6. 'detail' page is shown
7. -> click link
8. -> continuation loaded
9. -> redirected to 'search' page (with results of action)
10. 'search' page
Does that make sense?
Yes it does. What would be the best way to do 2.5? Can I submit an action using a link, other than masquerading form submission using $button->as_link.

Perhaps serializing the action submission into GET args would work but I don't know how to do that..

- Mikko
Mikko Lipasti
2008-04-01 10:04:45 UTC
Permalink
Post by Mikko Lipasti
Post by Alex Vandiver
This is what, for example, Seaside would do. Jifty doesn't do this
by default because it would mean continuations would pile up, one for
every page. You *can* do this if you want, but the way we generally
1. 'search' page with results
2. -> click link
2.5. -> also submit the search action with the link
3. 'search' page is reloaded (with results of action)
4. -> continuation saved
5. -> redirected to 'detail' page
6. 'detail' page is shown
7. -> click link
8. -> continuation loaded
9. -> redirected to 'search' page (with results of action)
10. 'search' page
Does that make sense?
Yes it does. What would be the best way to do 2.5? Can I submit an action using a link, other than masquerading form submission using $button->as_link.
Perhaps serializing the action submission into GET args would work but I don't know how to do that..
Ideas, anyone?
Sterling Hanenkamp
2008-06-16 03:13:56 UTC
Permalink
Post by Mikko Lipasti
Post by Mikko Lipasti
Yes it does. What would be the best way to do 2.5? Can I submit an action
using a link, other than masquerading form submission using
$button->as_link.
Post by Mikko Lipasti
Perhaps serializing the action submission into GET args would work but I
don't know how to do that..
Ideas, anyone?
(Mikko, sorry for answering late. I'm not sure I was the best authority and
I've been looking for a/starting a new job since the beginning of March.)

First, I want to answer the question and then I want ask it again in a new
context.

The answer is pretty straightforward, to send an action with a request, you
just need to submit the action again. For example:

Jifty->web->link(
label => 'View Details',
url => '/search_and_detail',
submit => Jifty->web->request->action('search-results'),
);

Any action that has been processed for the current request can be submitted
again and will be processed with the next request again. To perform the
intermediate jump, you can call tangent() from within a before rule of the
dispatcher.

before 'search_and_detail' => run {
tangent('detail');
};
on 'detail' => run { ... };

You can get the gist of all this from Jifty::Manual::Continuations. (I'm
mostly quoting that since I have not directly tested it recently, so if I'm
wrong, then this has changed.)

Now, my question is this: how do you do the same thing from within an
onclick handler that replaces a region?

I haven't figured out the right combination for saving a continuation
containing an action within the webservices call. I'm going through and
tracing out where continuations are saved and called out of requests as
generalized in the flow chart shown in Jifty::Manual::Continuations to learn
how this works in detail, but if someone can give me a hint in the meantime,
that'd be great.

Cheers,
Sterling

P.S. Look for me at the Grant Street Group booth at YAPC::NA. I won't be
making it in person :( , but I'm the poster child for their push to hire
telecommuting Perl hackers.

Loading...