Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Guidelines for User Data Validation ?

Thread view: 
Webby - 16 Mar 2004 19:15 GMT
Hi there,

I've been coding up some screens and dialogs and im totally unsure how I am supposed to be
validating user input. For instance if I have a dialog box with 3 JFormattedTextFields and an OK and
Cancel button am I supposed to check the data when the OK button is pressed or when each textfields
data is changed. I don't like the first approach and have been trying to implement the 2nd approach
however this seems harder than it first appeared :-

1) I started using a NumberFormatter (still am) plus setting up a enter key map to check the
validity of the entered data. If the data was ok it would be accepted for the field otherwise I got
a popup dialog to be opened which forced the operator to press an edit button or a undo button. The
edit selected all  field and they re-typed it in (same checks again after). If the undo button was
pressed the field was reset to its original value. This worked fine but I couldn't seem to get it to
work when the mouse was clicked elsewhere or the tab key was pressed to go to another field.
Basically I couldn't get the actionmap on enter and the tab and focus lost to all do the same check
and same action (popup a dialog if the data was wrong). In the focuslost case there seemed to be
some interference between the enter key opening a dialog and this causes focus to be lost on the
field !!!

2) I tried using an InputValidator on each field which stopped focus from changing if the data isn't
correct. I also fill in a error panel when this occurs telling what the problem is. This seems to
work ok but I haven't really seen it used elsewhere and I'm not really that keen on it.

So basically Im looking for some info on the preferred approach to how these things are done and
also if they are secure and don't have holes like my first try where there doesn't seem to be a way
of doing the same checks and actions on enter being pressed, focus being lost.

I personally think the best approach is to stop focus from being lost until the data is correct and
also popup a dialog telling them what the problem is giving the option of re-edit or undo. But as I
said I couldn't seem to get it to work properly for all possible events (enter, tab, lost focus
.... ).

There MUST be some simple way of doing a consistent check and action atleast for
JFormattedTextFields surely :( ??

Thanks for any info

Steve

Signature

Please remove 'y' from return address to reply (Anti Spam !!)

Karsten Lentzsch - 16 Mar 2004 21:07 GMT
I provide a demo around validation issues that highlights
different validation approaches, validation times, views.
In my opinion there's no single approach that fits all needs.
http://www.jgoodies.com/freeware/validationdemo/

I personally use a validation framework that can validate
on the server side or client side, in the domain layer,
a model layer, or in the presentation layer. The validation
can be performed by the objects itself that hold the data
or by associated validators that allow a more flexible
validation.

I favor to validate on the domain layer, so I can reuse
validation code on the server and client. But this works
only in special contexts (for example, the domain objects
must accept temporarily invalid data).

I'm using JFormattedTextFields with custom Formatters
or FormatterFactories as a forefront input filter and
to convert strings to the data types I operate on.

I personally favor to never block user gestures.
Locking down the focus can lead to blocked input
if you don't care about the validation context.
But better see the "Focus Lost Behavior" examples.

I plan to add more validation issues as demo users
suggest other approaches to validate, to provide
input hints, to render validation results, or to
mark invalid input.

Hope the demo helps you study the pros and cons
of some validation approaches.

Best regards,
Karsten Lentzsch
Webby - 16 Mar 2004 22:00 GMT
Wow Karsten thats some impressive work you have done there :)

I love the look and feel of your demo's wonderful stuff well done.

I don't suppose you could explain to me how you detect the focus change on components and also how
you are detecting the character change. I'd like to try these idea's on my dummy screen just to see
how it works but I don't seem to be able to get them to work consistently.

Thanks for the help

Steve
Webby - 16 Mar 2004 22:03 GMT
Oh by the way is that a textarea you are using to display the errors/warnings at the bottom of the
panel ? I didn't realise you could put icons in them !

Steve

> Wow Karsten thats some impressive work you have done there :)
>
[quoted text clipped - 7 lines]
>
> Steve
Karsten Lentzsch - 16 Mar 2004 22:19 GMT
> Wow Karsten thats some impressive work you have done there :)

Thanks for the compliments.

I bind domain model data to JTextFields and JFormattedTextFields
and commit text changes as value changes on different events:
character typed, focus lost, value commit action, valid edit.

Likely I'll talk about the binding and validation in a BOF
at this year's JavaOne. And I'm going to talk about it in
a session at the JAX 2004. Therefore I favor to put together
presentation slides that explain how everythings is tied
together, and how you can configure the binding, commit time,
validation, validation time, etc.

The tutorial for my Validation library already contain
the sources for the Validation Demo. I just need to
update the JavaDocs a little.

The demo uses different validation result renderers:
JLabel, JTextArea, and a JPanel that consists of a
JLabel and JTextArea. The JLabel is bound to the
severity of the validation result, the text area
to the validation messages localized text. I plan
to add a JTable validation result view too.

Hope this helps.
Karsten
Steve Webb - 17 Mar 2004 09:47 GMT
I had a look on your site Karsten but I failed to find any code or
documentation for the validation demo ?

Cheers

Steve
Karsten Lentzsch - 17 Mar 2004 10:06 GMT
> I had a look on your site Karsten but I failed to find any code or
> documentation for the validation demo ?

The Validation library and tutorial sources are not yet
available to the general public, they ship in a product.

Validation is already a project at JavaDesktop.org,
but I it's non-public with only a few expert observers.

I plan to open source the Validation library as well
as the Binding library. It's just that I need money
to live and eat and feed my family. Product revenues
and sponsors finance my Java desktop activities.
There more people license my Swing Suite the earlier
I can open source the existing libs and can proceed
and create new solution, examples, tutorials.

Also, I hold back Validation a little until there's
a tutorial and demo for the Binding library. Both
libraries are independent, but most Validation tutorial
items are easier to understand if you know about Binding.

Due to the time constraints for the upcoming conferences
and talks about Binding and Validation there will be
more material about both issues: binding and validation.
And I hope that some professional users can justify
the costs to license the Swing Suite product so I can
open more parts.

Hope this clarifies the situtaion. Best regards,
Karsten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.