Hi Janek,
iŽve seen the examples just before i wrote my question.
In the examples you havenŽt several input formats, a invalid fieldvalue always
return null and there is none possibility to change the fieldvalue.
With the code below i tried to get the several Input formats for a date.
Please take another look at my first request.
Thanks
Asterios
public class UIDynamicDateDataType extends UIDateDataType {
public Object convertToObject(String newString, Object previousValue) throws
DataTypeConversionException {
if (newString!=null && (newString.length()==6 || newString.length()==8 ||
newString.length()==10)){
String dateFormatStr=null;
switch (newString.length()){
case 6:
//ddmmyy
if (!String.valueOf(newString.charAt(5)).equals("."))
dateFormatStr="ddMMyy";
break;
case 8:
//dd.mm.yy
//ddmmyyyy
if (String.valueOf(newString.charAt(5)).equals("."))
dateFormatStr="dd.MM.yy";
else
dateFormatStr="ddMMyy";
break;
case 10:
//dd.mm.yyyy
dateFormatStr="dd.MM.yyyy";
break;
}
if (dateFormatStr==null)
return null;
Date returnDate=null;
SimpleDateFormat simpleDateFormat=new SimpleDateFormat(dateFormatStr);
try{
simpleDateFormat.setLenient(false);
returnDate = simpleDateFormat.parse(newString);
}
catch (ParseException e){
JOptionPane.showMessageDialog(null, "alert", "alert",
JOptionPane.ERROR_MESSAGE);
return null;
}
if (returnDate!=null){
simpleDateFormat=new SimpleDateFormat("dd.MM.yyyy");
newString=simpleDateFormat.format(returnDate);
return (Object)super.convertToObject(newString, previousValue);
}
else {
JOptionPane.showMessageDialog(null, "alert", "alert",
JOptionPane.ERROR_MESSAGE);
return null;
}
}
return null;
}
}
*Von:* <[email protected]>
*Gesendet:* 02.02.07 19:07:38
*An:* "Asterios Kontonikos" <[EMAIL PROTECTED]>
*CC:* <[email protected]>
*Betreff:* RE: [ULC-developer] Using DateFields
Hi Asterios,
Please see the following links:
http://lists.canoo.com/mailman/private/ulc-developer/2004/001037.html
http://ulc-community.canoo.com/snipsnap/space/Validation+Components
Hope this helps.
Thanks and regards,
Janak
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Asterios Kontonikos
Sent: Thursday, February 01, 2007 6:28 PM
To: [email protected]
Subject: [ULC-developer] Using DateFields
Hello,
i want to use datefields with several input (formats) e.g.:
ddMMyyy
dd.MM.yy
ddMMyyy
dd.MM.yyy
At FocusLost the datefield should be formatted with dd.MM.yyyy
or by an incorrect input should appear an Error Message.
At FocusEnter the datefield should be formatted with dd.MM.yyyy (valid
input)
or the incorrect value appear.
In the first step i use DateDataType to format and validate
ULCTextFields with format pattern dd.MM.yyyy.
It works fine until i enter a valid Date with this format.
I get field Value Null when we enter an incorrect Date
but not a Message about it. I try to check the FieldValue by
FocusLost ourselves but we get NULL at an incorrect Date.
In the second step i use convertToObject (UIDateDataType) to get the
entered value for validation and formatting. The convertToObject Method
fires on each Keystroke.
Here i can format the entered Value with dd.MM.yyyy but its much complex.
When the field gots the focus the value isnt formatted and appears so
inputted.
I search for a method to format and validate
an datefield on the FocusLost Event with the possibility to set the value.
I have seen your Examples in the ULC Developers List at these subject but
cant
got the right idea.
Thanks
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066
Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
Gleich testen! *http://www.pc-sicherheit.web.de/freescan/?mc=022222*
[http://www.pc-sicherheit.web.de/freescan/?mc=022222]