As far as date validation are concerned , declare the date variable as string in your view bean,
Add regular expression validation in the validation file. <field-validator type="regex"> (((((((0[13578])|(1[02]))[\/]((0[1-9])|([12]\d)|(3[01])))|(((0[469])|(11))[\/]?((0[1-9])|([12]\d)|(30)))|((0?2)[\/]((0[1-9])|(1\d)|(2[0-8]))))[\/](((19)|([1-9][0-9]))([\d][\d]))))|((0?2)[\/](29)[\/](((19)|([1-9][0-9]))(([02468][048])|([13579][26])))))$ </field-validator> once validation passes you can convert the string to date and used the same in the service layer. Hope its work for you. carl ballantyne wrote: > > Hi All, > > I have a Person object with a birthday attribute which is a Date. In > the form I have a textfield to enter the value. I want the field to > display the date in the format dd/MM/yyyy and the validation to apply > using that format. However everything I am trying does not work. > > I tried putting "format.date = {0,date,dd/MM/yyyy}" in the properties > (http://struts.apache.org/2.1.8/docs/formatting-dates-and-numbers.html) as > I > am apparently supposed to but this does not display the date in the > correct format via the s:date tag or the s:textfield tag and the > validation does not work. Via the s:date I get "Nov 16, 1976 12:00:00 > AM" and via s:textfield I get "11/16/76 12:00:00 AM.000". If I try and > put a date in the format dd/MM/yyyy it tells me it is in an invalid > format. It only accepts MM/dd/yyyy. > > I also tried adding "struts.date.format = dd/MM/yyyy" to the > properties file for my package. > (http://struts.apache.org/2.1.8/docs/date.html). This seems to work a > bit better. The date is displayed in the correct format via the s:date > tag. However the s:textfield displays it as "11/16/76 12:00:00 > AM.000". And the validation works the same as before, ie only accepts > MM/dd/yyyy dates when I really want dd/MM/yyyy. > > I am not using a custom Date Converter because the guide says not to > use it to display i18n formatted dates. Do I need to resort to this? > > It just seems I am doing something wrong as it should not be this > difficult. How do you guys deal with converting date strings? > > Cheers, > Carl. > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > -- View this message in context: http://old.nabble.com/s%3Atextfield-and-date-format-as-dd-MM-yyyy-tp26197512p26199380.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org