[Bese-devel] actions and broswer refresh

Attila Lendvai attila.lendvai at gmail.com
Fri Apr 21 15:40:48 UTC 2006


> >recently i've discovered that if i render an action with action-href,
> >press the link, and then refresh the browser, then the action is
> >triggered again.
> >
> >is this the expected behviour?
> >
> of course it is! :) imagine (<ucw:a :action (display-current-time self)
> ...). click on it, now hit 'back', and then click on the link again.
> You'd expect the time to update, right? i would. or a page with a
> meta-refresh that shows the 'current' news items....

now i think i can formulate my problem better: when an action is
triggered the document url is rewritten to contain the session,frame
and action params.

if you refresh your browser after that, then it will GET that link, so
ucw will fire the action again. and this is what bothers me.

imagine the following situation: a pageable table is displayed, user
presses next page, something (network) goes wrong while rendering the
page, gets impatient and refreshes the page. now we just stepped two
pages, which is highly unintentional.

unfortunately i'm no http/js guru, so i can't really "fix" this due to
missing the bird's view. but i modified action-dispatcher's dispatch
with partial success. (see code at the end of the mail)

what i changed is that when it can sucessfully identify a session/form
then it will handle the request no matter if an additional action can
be identified or not. but of course, if an action is also found then
it's executed.

after that if delete the a=... param from the link the action will not
be executed again and the proper page will be rendered at a refresh.

the only problem left is keeping the action param away from the
request until a user interaction explicitly sets it. maybe it could be
done by js + cookies?

as a side note: i'm already wrapping my entire page in one form tag so
that when there are multiple logically disconnected forms on one page
then submitting one will not lose the others' entered data. because of
this all my links are done with onclick js already. so it's not a big
problem if they must set cookie params or something.

any toughts? if it's not BS and somebody gives me the bird's view/impl
strategy, then i'm willing to implement it.

- attila

(alias 101 on irc &no 'its not lisp code :)



(defmethod dispatch ((dispatcher action-dispatcher)
                     (application standard-application)
                     (context standard-request-context))
  (when-bind session (find-session application context)
    (setf (context.session context) session
          (session.last-access session) (get-universal-time))
    (ucw.rerl.dispatcher.dribble "Found session ~S." session)
    (when-bind frame-id (find-frame-id context)
      (ucw.rerl.dispatcher.dribble "Found frame-id ~S." frame-id)
      (when-bind frame (find-frame-by-id session frame-id)
        (ucw.rerl.dispatcher.dribble "Found frame ~S." frame)
        (setf (session.current-frame session) frame)
        (reinstate-backtracked frame)
        (call-callbacks frame (context.request context))
        (if-bind action (find-action frame (find-action-id context))
          (progn
            (ucw.rerl.dispatcher.dribble "ACTION-DISPATCHER matched,
calling action ~S." action)
            (make-new-frame (context.session context))
            (with-action-error-handler ()
              (funcall action))
            (render-loop (frame.window-component
(context.current-frame *context*)))
            (save-backtracked (context.current-frame *context*)))
          (render-loop (frame.window-component (context.current-frame
*context*))))
        t))))


More information about the bese-devel mailing list