• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2: date validation

 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The current date validation in Struts 2 seems to target only for a range. How do I validate the value against a specified format?

I tried to use the required validator to ensure that the field is mandatory, but the check appears to pass through.

Is it a current limitation in the Struts 2 framework?


16:30:07,920 ERROR DateTimePicker:316 - Could not parse date
java.text.ParseException: Unparseable date: ""
at java.text.DateFormat.parse(Unknown Source)
at org.apache.struts2.components.DateTimePicker.format(DateTimePicker.java:309)
at org.apache.struts2.components.DateTimePicker.evaluateParams(DateTimePicker.java:209)
at org.apache.struts2.components.UIBean.end(UIBean.java:481)

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In strut2 the input date format defaults to the current locale.

If a different input format has to be specified say yyyy-MM-dd,
then implement a new class say DateConverter extending StrutsTypeConverter.

Specify this new class in the xwork-conversion.properties:
java.util.Date=com.myown.web.converter.DateConverter

This should help...
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What am I saying is that, suppose the user entered a date not in the required format, or didn't even provide a date, the default Struts 2 validation doesn't appear to stop it, hence the exception arises?
 
Not so fast naughty spawn! I want you to know about
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic