This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes centeralizing key captures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "centeralizing key captures" Watch "centeralizing key captures" New topic
Author

centeralizing key captures

Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
So, we have a web application which displays a bunch of documents to the user. The page that we display to the user has a bunch of Frames, IFrames and DIVS. Maybe around 6-7 of them. We are providing support for keyboard based navigation; ie; if user presses up, we move to next document, down for previous document, Pgup for next page, PgDown for previous page, and so on. There are about 10 differrent keys that we need to handle. The keyboard handlers are spread out all over. 4 othem in one frame, 2 of them in another DIV, and so on. It's a mess.

Now, what happens is that the frame that has the focus gets all the keyboard input, and sometimes the application becomes unresponsive to keyboard input (our keyboard handlers don't get called). We have to make the user click on a frame, so that the frame gets the focus, and then press keyboard, which is silly, because the idea behind keyboard navigation is that user doesn't have to use the mouse.

So, is there any way I can centeralize all my keyboard handling. It would be much easier to maintain if all keyboard handling was in one place, but we need to make sure that no matter which frame has focus, the centeralized keyboard handler gets called.

The only thing that I think of is to make each frame implement keyboard handling. Every frame should bubble up the event to it's parent, which will bubble the event upto it's parent, until we reach grand-daddy of all frames, that can handle all keyboard events and call the appropriate functions on the child frames based on the business logic. But, in this soultion we will have to change the code in each and every frame. That's a nightmare, which is compunded by the fact that each frame individually loads differrent jsp pages. So, I have to add the bubbling code to maybe 15-20 jsp's. Does someone have a better solution? We don't mind implementing hacks for now, even *flame retardent suit on* IE hacks. We are getting close to release, and we will have time to put a robust solution for the next release. We need to refactor that page for performance reasons, anyways. So, any suggestions for hacky and/or robust soultions are appreciated.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The easiest solution in my eyes would be to apply a js file to every page with the js file containing your event handlers, (I personally hate frames!) Therefore all of your frames would have the logic in it.

You can force a focus on a frame by using
parent.frameName.focus();
that may help you from having the user click the page.

The unresponsivness is normally caused by the page not being focused. For example open up two browsers. Select one of them and close it. Look at your toolbar, you will see that other pages button is not depressed. if you try typing, nothing would happen since the page is not active. Click on the page and it becomes active.

Eric
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
Originally posted by Eric Pascarello:
The easiest solution in my eyes would be to apply a js file to every page with the js file containing your event handlers, (I personally hate frames!) Therefore all of your frames would have the logic in it.

You can force a focus on a frame by using
parent.frameName.focus();
that may help you from having the user click the page.

The unresponsivness is normally caused by the page not being focused. For example open up two browsers. Select one of them and close it. Look at your toolbar, you will see that other pages button is not depressed. if you try typing, nothing would happen since the page is not active. Click on the page and it becomes active.

Eric


Exactly!! the page loading and frame refreshes make the focus go all over the place, and I'm not sure where the focus is going to land. On top of that there is no indication to the user which frame has the focus.

I hate frames too!! But, it's a legacy system, and there is a lot of stuff in there.

Setting the focus to a frame is an interesting ide. Maybe I can put a timer that keeps setting focus on the parent frame. However, some of the frames display textboxes sometimes, and we do need to allow the user to type in the textbox. So, if I set the focus to the parent frame, will the user be able to type in the text box?

Having the event handlers in the js files sounds interesting too, but won't I have to change code in the jsp to call my handlers in the js too? Nonetheless, this idea is simpler than my "bubbling up" idea. I will try it out. Thanks!!
 
wood burning stoves
 
subject: centeralizing key captures
 
Similar Threads
User session and refresh frames in jsp
breaking out of frameset upon Actionforward
Alt + Tab swapping issue
setting focus of a JInternalFrame
Frame/Frameset Framework