Hum... Maybe I'm not very clear.
Here is my custom converter that i register in the
xwork-conversion.properties (by adding
java.util.Date=com.blabla.DateConverter) :
import ognl.DefaultTypeConverter;
public class DateConverter extends DefaultTypeConverter
{
//~ Methods
////////////////////////////////////////////////////////////////
public Object convertValue(
Map context,
Object o,
Member member,
String s,
Object value,
Class toType)
{
if( value == null )
return null;
Object result = null;
if (toType == String.class)
{
if (value instanceof Date)
{
Date sa = (Date) value;
SimpleDateFormat sdf = new
SimpleDateFormat("dd/MM/yyyy");
result = sdf.format(sa);
}
}
else if (toType == Date.class)
{
if (value instanceof String || value instanceof String[])
{
String sa;
if(value instanceof String[] )
sa = ((String[]) value)[0];
else
sa = (String) value;
SimpleDateFormat sdf = new
SimpleDateFormat("dd/MM/yyyy");
try
{
result = sdf.parse(sa);
}
catch (ParseException e)
{
result=null;
}
}
}
else
throw new UnsupportedOperationException("Conversion d'une date
en
"+toType.getName()+" n'est pas implementee.");
return result;
}
}
"Ahh... Good question... I guess you don't want to see 2 messages? 2"
"messages might be ok:"
"Your text "Foo Bar" could not be parsed as a date"
"You must enter a date for birthday"
My question : how can i do to see the message "Your text "Foo Bar" could not
be parsed as a date", what can i do in my dateconverter to add a FieldError
????
Cheers.
Richard.
-----Message d'origine-----
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] la part de
Jason Carreira
Envoye : jeudi 25 septembre 2003 20:40
A : [EMAIL PROTECTED]
Objet : RE: [OS-webwork] Validation Framework details
> -----Original Message-----
> From: Fred Lamuette [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 25, 2003 1:58 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [OS-webwork] Validation Framework details
>
>
> You have a model class in your action to populate, one of the
> property is a java.util.Date. You register your own
> DateConverter (for i18n purpose ...) When WW2 populates the
> Action after a form submission, you have 2 cases : 1/ The
> string represent a date, and the converter can parse it and
> store it in the model class. No pb. 2/ The string doesn't
> represent a date, your converter surely returns a NULL value.
> The date property in the model class is set to NULL. You can
> always validate that the property MUST be not null, but the
> main aim is to warn the user it is an invalid date.
>
> So my question is : if validation triggers after populating
> the model class, how can you validate an input parameter is
> not in a bad format ?
>
> Cheers.
> Richard
Ahh... Good question... I guess you don't want to see 2 messages? 2
messages might be ok:
Your text "Foo Bar" could not be parsed as a date
You must enter a date for birthday
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork