PermaLinkShow 'n Tell Thursday #209:29:01 AM
Written By : Scott Good

Technorati tags: ,

OK, I'm late. This was due Thursday and today is Friday. So sue me. Aren't you supposed to save the best things for last? ShowAndTellFriday.jpg In any case, I'm here and I have a good tip for you, so read on.

If you do web development with Domino, you've probably fought the problem of how to get back to where you came from. What? You don't know what I'm talking about? Sure you do; let me say it more clearly:

You open a database in your browser. You're in the default view. You change to another view more appropriate to whatever it is you're doing. Because you can only see some of the documents in that view at one time, you click Next Page, Next Page, Next Page...a few times to get to where you want to be.

Then you expand one category of the view, then expand another category, then expand again to show the responses to a particular document, which is where you need to do some work. You find the document you want, open it, do whatever it is you were going to do and then save it.

This is where the problem starts.

At the end of the save you find yourself back at the top of the view. More often than not, it's not only back at the top of the view, it's at the top of the default view. If you need to do something to the document right next to the one you just left, well, you have to start the whole darn process all over again.

Switch view. Next Page. Next Page. Next Page. Expand. Expand. Expand. Finally, click, into the document you were right next to a few minutes ago.

It's frustrating. It's maddening. And, worse, it's completely unnecessary. Yeah, that's right: It doesn't have to be that way. Let me explain:

To start fixing it you first have to ask yourself, "So, what's causing this in the first place?" The problem has to do with how the application is figuring out where to send you after the save.

There are only a few ways to redirect the browser after a save. Only a few that I'm aware of, anyway. One is to use a $$Return field. I know there are people out there who use these all the time but I have had absolutely no luck making an intelligent $$Return. Maybe it's my technique, maybe you just can't do it. I don't know, but when I see an application forcing users back to the top of the wrong view after a save I immediately start looking for a $$Return field. It's usually a dead give-away.

Don't like 'em. Don't use 'em. Ever.

What I do use are WebQuerySave agents. I've talked about this in many of my sessions at Lotusphere and the Advisor events but still a lot of people don't know about it: You can use WebQuerySave agents to control the browser. Here's how:

When you run an agent in the Notes client, any Print statements...

Print "Processing document #" & i

...are sent to the status bar at the bottom of the client. It's a nice way to let users know your process hasn't died on them somewhere along the way.

That same Print statement used in a background agent sends the text directly to the Notes Log. It's a nice way to completely piss off your Notes Administrators as you fill their logs with trivial and meaningless information.

But, in a WebQuerySave agent, Print statements are written straight to the browser as HTML. One possible use of this might be to format a nice Thank You screen that picks up a few things from the document (the title, the user's name, whatever) and puts it out to the user to confirm whatever you've done. That's all well and good, but it doesn't solve the problem of getting back to where you came from in the view.

Or does it?

Actually, it does. Or, can. You see, since you can send HTML to the browser, you can also send JavaScript which, at the end of the day, is just smart HTML. With JavaScript you can do lots of different things, one of which is direct the browser to a URL. You could, for instance, do something like this:

Print "<script>"
Print "    window.location='http://www.scottgood.com';"
Print "</script>"

That little bit of JavaScript will direct the browser to go to this blog, probably not where you wanted your users to end up, but you could easily enough change it to send them where you do want them to go. The only problem is, it still doesn't solve the problem. This, really, is just as bad as the $$Return because it's going to a fixed URL--the same thing that makes the $$Return relatively useless.

So, what's a coder to do?

[A disclaimer here: There are several ways to skin the cat I'm about to skin for you. This solution is a quick, easy, fix if you're using a frameset. If you're not, there are similar techniques you can employ to end up in about the same place. I'm just not going to go into them today.]

The root of the problem here is that the URL you hope to go back to keeps changing. While you may have started at:

http://www.myserver.com/db.nsf/AllDocuments

After a little clicking around in the view you end up at a URL more like this:

http://www.myserver.com/db.nsf/AllDocuments?OpenView&Start=137&Count=200&Expand=13.3.1.2#13.3.1.2

Every click of the mouse changes the URL, so you can't possibly hard-code it into your application. What you have to do is find a way to reliably get a handle to the place you came from.

One approach is to try to use the HTTP_Referer address in your form, but that isn't reliable. When you first open a document from a view, it's good, but by the time you get into the WebQuerySave agent, it's not. By then, the form is the referrer. Also, HTTP_Referer changes if you have anything on your form that causes a refresh, like a (perish the thought) non-DHTML tabbed table or a keyword field that refreshes its values.

What you need is a reliable place from which you can consistently retrieve the last URL of the view you last left. So, what knows the URL of the view? The view does, of course. If you're using a $$ViewTemplate form (please use a $$ViewTemplate form), you can put field named Path_Info_Decoded on the form and it has, you guessed it, the URL you're currently visiting.

So, (this assumes a frameset), let's say you have a left-hand frame called "left," and main frame called "main." In the Page or Form that's loaded into the left frame, define a JavaScript variable:

<script>
    var curViewLoc;
</script>

Then, in the $$ViewTemplate, create a ComputedText area that takes the value from Path_Info_Decoded and uses it to set the value of curViewLoc in the left frame:

"<script>window.parent.left.curViewLoc=\"" + Path_Info_Decoded + "\";</script>"

Whenever the $$ViewTemplate form loads (which is whenever you click on a twistie or navigate to a new location), this function will reset the value in the left frame. However, when you open a document and navigate around in it, the value doesn't change in the left frame because there's nothing in your regular forms to change it.

Soooo....

In your WebQuerySave agent, you can write a little JavaScript in a few Print statements to retrieve and use the value of curViewLoc from the left frame as the new location to return to from the main frame:

Print "<script>"
Print "    window.location=window.parent.left.curViewLoc;"
Print "</script>"

Just as easy as that.

Comments :v

1. Rob McDonagh02/24/2006 07:22:03 PM
Homepage: http://www.CaptainOblivious.com


That's cool. I've seen something similar with cookies, but I think I like this better. I know all the techniques you used, of course, but I didn't put them together like that. Which is why SnTT posts rock!




Enter Comments^


Email addresses provided are not made available on this site.





You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links


:-) :cry: :-\ :huh: ;-) :cool: :grin: :emb: :laugh: :-p :lips: :-( :rolleyes: :-o :-D :angry: :-x
bold italic underline Strikethrough





Remember me    

Disclaimer & Copyright
Monthly Archive
Contact me...
Racing sponsors and such...

Thank you sponsors!

GABlogLogo.jpg

GOODAero

GOODAero specializes in building aerodynamic products for racing cars. Our first product, the GOODAero Raptor wing is available at a surprisingly reasonable price (under a grand) for a full carbon, full-sized, racing wing. Check it out.


Infinite Fiberworks Co, a great source for high-quality Porsche fiberglass parts

Infinite Fiberworks Co.

If you are looking for fiberglass for Porsches, IFC is the place to go. I have used parts from most of the major suppliers and IFC's are easily the highest quality and the most reasonably-priced. Contact Mike at Infinite Fiberworks for more information.

Located in Racine, OH (so far Southeast they're almost in West Virginia), IFC's goal is to be The Best. Give 'em a try.


Bent or ugly wheels? Call Wheel Medic!

Wheel Medic & The Round House

Whether you need to repair, repaint, refinish or just replace your wheels, the guys at Wheel Medic/Round House can get you back on the road in no time!

Wheel Medic, Inc is a family-owned company which specializes in the repair and restoration of aluminum wheels.

The Round House was founded to service Wheel Medic's clients looking for more than just repair work...from custom wheel colors to high-end wheel applications and body kits, the Round House is there to serve the discriminating automotive enthusiast.


Used Porsche parts, great prices!

A Part Above

Looking for used parts for 944s, 924s, 968s or other late-model water-cooled Porsches? Contact John at A Part Above.

Located in Strongsville, OH (20 miles south of Cleveland) their goal is to provide top quality parts and services. I can tell you, John is great to work with and the prices? Very hard to beat.


SMRT Motorsports wants you!

SMRT (that's short for Skid Mark Racing Team), a very-

loosely organized band of fun-loving friends who enjoy auto racing (heck, cars in general), and the occasional adult beverage, wants you to be a part of our team.

Go here to find cool T-shirts, sweatshirts, caps and mugs with the SMRT team logo.

The BlogRoll
Lotus Domino ND6 RSS News Feed RSS Comments Feed Geo URL RSS Validator Blog Admin Lotus Geek Open Notes Picture Database OpenNTF BlogSphere
Calendar
February 2012
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
By Category
What I do for a living


I am the President of Teamwork Solutions a long-time Lotus, now IBM, Premier Partner.

With offices in Columbus and Cincinnati, Ohio, we specialize in custom application development for IBM Lotus Notes, Domino, and related technologies. Our software product, ProcessIt! (see below), is quite possibly the world's best, most powerful and easiest-to-use workflow tool for Notes and the web.

Our clients are some of the world's largest corporations along with others that aren't so big.

We do excellent work, quickly, and often on a fixed-fee basis. We'd love to talk to you about your next project.




I am a Contributing Author to Lotus Advisor Magazine, with more than 40 articles under my belt.

I've written how-to series (serieses?) on LotusScript, JavaScript, Cascading Style Sheets (CSS), and now, AJAX (Asynchronous JavaScript and XML), as well as a bit on miscellaneous web development topics.


TheView.jpg

I also write for The View as of the July/August issue where I showed how to take an ugly Notes applications and make it beautiful with just a few minutes' (careful) work.



I am the chief architect and one of two primary developers for what many consider the best all-around workflow tool for Notes/Domino, anywhere, regardless of price.

It's called ProcessIt!, and you can read all about it at www.notesworkflow.com but the bottom line is this: ProcessIt! is fast and easy to learn, extremely powerful, and can be used by mortals. Even--dare I say it?--common users.

You can spend a lot more on a workflow tool but you won't be able to do a lot more for all the extra money.

Don't believe me? Download and try it for free for 60 days.



GTSLogoSm.gif
Copyright Porsche and NASA...not me!

I race a Porsche 944 S2 in National Auto Sport Assocation events and am the 2008 National Champion in NASA's GTS2 class.

Blame this event, a few years ago, for starting that particular money drain all over again.

In support of my habit, I am the NASA Great Lakes Region's GTS (German Touring Series) Director.

I'm also a Nationally-Certified Instructor for the Porsche Club of America and am in charge of classroom sessions for the Mid-Ohio region when we are doing high performance driving events.

In a prior racing life, I was the Midwestern Regional Formula Atlantic Champion and, in 1991, the Ohio Vally Region of SCCA's Regional Driver of the Year (but that, alas, went away when my credit cards let go of the rope!).




I'm writing a book...or at least trying to.

It's murder mystery in which, not too surprisingly, the main character runs a small software company and races cars for fun. Oh yeah, and lives near where I do.

Just where do they come up with these crazy ideas?

Facebook