From: Roedy Green on 18 Mar 2010 14:18 On Thu, 18 Mar 2010 14:40:02 +0000 (UTC), Rhino <no.offline.contact.please(a)example.com> wrote, quoted or indirectly quoted someone who said : >I'm trying to think of a good design for a hypothetical validation of a >date and would appreciate some suggestions. Have a look at BigDate. It is step toward what you want. See https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fcommon11%2FBigDate.java -- Roedy Green Canadian Mind Products http://mindprod.com Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, �How would I develop if it were my money?� I�m amazed how many theoretical arguments evaporate when faced with this question. ~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
From: John B. Matthews on 18 Mar 2010 15:09 In article <hntksh$kr8$1(a)news.eternal-september.org>, markspace <nospam(a)nowhere.com> wrote: > new JFormattedTextField( new SimpleDateFormat("mm/dd/yy")); > > You can also use the InputVerifier class to get a more general range > of behaviors: > > JTextField field = new JTextField(); > field.setInputVerifier( new InputVerifier() { ... > > Neither does exactly what you want, but they're standard in the API and > you might be able to adapt them to your current situation. Here's an example that supports multiple formats: <http://groups.google.com/group/comp.lang.java.programmer/msg/d9f7a7702139b48f> > If you're using something like JSF for web apps, that's a little > different, but JSF still has standard validation methods. -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Daniel Pitts on 18 Mar 2010 17:33
On 3/18/2010 7:40 AM, Rhino wrote: > I'm trying to think of a good design for a hypothetical validation of a > date and would appreciate some suggestions. You might want to look into Spring Binding. Its part of the Spring Framework. They have a very decent validation framework. The approach that they take is that there is a Validator class which will register problems with an Errors object. The errors object then will have a list of errors (global and/or field specific) that can be presented to the user. It also handles "conversion" errors. If you have a form submission that has string values, but your backing bean has Dates, Integers, or Frobitzs, etc, it will try to convert them. If any conversion fails (throws an exception for instance), then the binder will add that to the Errors object. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/> |