You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Rubens Gama <ru...@sefaz.ce.gov.br> on 2001/10/24 15:02:15 UTC

Type Date is a problem.

how i can solve the problem DATE type of a FormBean's property?

the ActionServlet cannot set a property DATE.

I need help.

Thanks.

RE: Type Date is a problem.

Posted by Rubens Gama <ru...@softsite.com.br>.
your solution will be my solution...
thank you.

-----Original Message-----
From: Deadman, Hal [mailto:hal.deadman@tallan.com]
Sent: quarta-feira, 24 de outubro de 2001 18:09
To: struts-dev@jakarta.apache.org
Subject: RE: Type Date is a problem.


Make a get/set that accepts a String for each of your form date fields.
Parse the string into a Date in your validate method. If it doesn't parse
correctly then use report an error to the user.

Use a method like this to parse your Dates. A null return value indicates an
invalid date.

    protected java.util.Date parseDate(String dateString, String format)
    {
        if (dateString == null)
        {
            return null;
        }
        try
        {
            DateFormat df = new SimpleDateFormat(format);
		// setLenient avoids allowing dates like 9/32/2001 which would otherwise
parse to 10/2/2001
            df.setLenient(false);
            return df.parse(dateString);
        }
        catch(ParseException pe)
        {
            return null;
        }
    }

-----Original Message-----
From: Rubens Gama [mailto:rubensgama@sefaz.ce.gov.br]
Sent: Wednesday, October 24, 2001 9:02 AM
To: struts-dev@jakarta.apache.org
Subject: Type Date is a problem.
Importance: High


how i can solve the problem DATE type of a FormBean's property?

the ActionServlet cannot set a property DATE.

I need help.

Thanks.


RE: Type Date is a problem.

Posted by "Deadman, Hal" <ha...@tallan.com>.
Make a get/set that accepts a String for each of your form date fields.
Parse the string into a Date in your validate method. If it doesn't parse
correctly then use report an error to the user.

Use a method like this to parse your Dates. A null return value indicates an
invalid date.

    protected java.util.Date parseDate(String dateString, String format)
    {
        if (dateString == null)
        {
            return null;
        }
        try
        {
            DateFormat df = new SimpleDateFormat(format);
		// setLenient avoids allowing dates like 9/32/2001 which would otherwise
parse to 10/2/2001
            df.setLenient(false);
            return df.parse(dateString);
        }
        catch(ParseException pe)
        {
            return null;
        }
    }

-----Original Message-----
From: Rubens Gama [mailto:rubensgama@sefaz.ce.gov.br]
Sent: Wednesday, October 24, 2001 9:02 AM
To: struts-dev@jakarta.apache.org
Subject: Type Date is a problem.
Importance: High


how i can solve the problem DATE type of a FormBean's property?

the ActionServlet cannot set a property DATE.

I need help.

Thanks.