Re: handling focusLost Events
From: Paul Lutus (nospam_at_nosite.zzz)
Date: 10/21/03
- Previous message: may: "Accessing resources(files) outside WAR application file"
- In reply to: Nuggy: "handling focusLost Events"
- Next in thread: Chris: "Re: handling focusLost Events"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 21 Oct 2003 11:36:04 -0700
Nuggy wrote:
> Ok, I'm ready to toss this thing across the room. Here's what I'm
> trying to accomplish, greatly simplified:
>
> I have a screen with several text fields. I want to validate the
> entry in each text field when the user tabs out of it to the next one
> (some fields are required). If they enter an invalid entry or leave
> it blank, I want to display a pop-up in the form of a
> JOptionPane.showMessageDialog to inform them of the problem, then
> reset focus to the invalid field.
>
> Here's the problem: fields a, b, and c are all validated this way,
> and are sequential in the focus order. In a new screen, if the user
> enters an invalid value into field a, field b briefly gets the focus
> from the tab key, and in the course of popping up the box and
> resetting focus to field a, field b loses this brief focus, gets
> validated because of this, and I end up with two and sometimes three
> pop-up boxes that I don't want. I am using isTemporary(); without it
> I end up in an infinite loop of popups.
Classic deadlock error. Create a flag that prevents this. If you see the
need to create a validation dialog, first set a "busy" flag, then show the
dialog. In your event handler code, first test the flag, if it is set, do
nothing.
Once the dialog is dismissed and the focus has been reset to the previous
field, then clear the flag. This allows the event handlers to function
normally again.
> I've spent two days trying ideas and I'm still plagued by these
> "phantom" popups.
All you have to do is think it through. Your event handlers think any
focus-lost event is equal to any other. But they are not the same -- some
are initiated by the user, and some by your dialog.
-- Paul Lutus http://www.arachnoid.com
- Previous message: may: "Accessing resources(files) outside WAR application file"
- In reply to: Nuggy: "handling focusLost Events"
- Next in thread: Chris: "Re: handling focusLost Events"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|