TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 and former Developer Advocate with Google now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 241 other followers

  • Sleepless Nights…

    November 2005
    S M T W T F S
    « Oct   Feb »
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  
  • Blog Stats

    • 857,971 hits

Updated Web State Machine Code Supports Back Button

Posted by David Chandler on November 28, 2005

I’ve updated the Web state machine example from my earlier CFDJ article. You can find the updated code here:

WebStateMachine1_1.zip

It now implements the POST-REDIRECT-GET (PRG) pattern and uses a page token to allow the back button to work better. I also updated the following files:

  • sendEvent.cfm now appends pageToken to URL
  • choose_customer.cfm removed form action attribute to show that sendEvent adds it
  • choose_products.cfm removed form action attribute to show that sendEvent adds it

Refresh now works perfectly courtesy of PRG. The back button is trickier because when you click it, the browser actually loads its cached copy of the page, but what’s on the previous page no longer represents what’s stored in the user’s Session scope. So when you then click something on the page, you’re going forward again and will get to the right view state, but may see data from the future on your page. For example, in the sample app I’ve written, if you select two products, then use the back button, you will see a screen showing one product. But when you select another product, the page you get will show all THREE items you’ve now selected as far as the Session is concerned.

If you want to get really fancy, you can write code that keeps track of all the variables created in each state and “roll back” to your previous state by deleting any variables created forward from that point. Another possible solution is to use CFHTTPHEADER to set the no-cached directives. Then, when you click Back, the browser will be forced to make a trip to the server and the previous view will be shown with now current data.

If you get an error condition, you can display a hyperlink like “Resume what you were doing” with a link to flowctl.cfm. That will at least get the user back to the state that’s current on the server.

Good luck!
/dmc

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: