• 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

How to validate time field using validator framework of struts

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I'm trying to valitade a time field in a form using Struts-validator (Struts 1.2). This is how I've configured validation.xml:
<form ....>
...
<field property="time" depends="required,date">
<arg0 key="test.time"/>
<var>
<var-name>datePattern</var-name>
<var-value>HH:mm</var-value>
</var>
</field>
...
</form>

The problem is that the validator always raises an validation error, no matter what data is informed, for example, like this 13:00.

Is my validation.xml correct? How do I validate a Time field?

Thanks in advance.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't look like a Java question. I'm moving it to the Struts forum.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works fine for me. Are you using client-side(javascript) validation or server-side validation?
 
tushar joshi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using this at server side validation.
it works fine for date format but fail to validate for time.
actually i am using this in web services to validate input data.
by using GenericValidator.

can u please help me?

Thanks in advance.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there is any existing validation pattern for the time hh:mm. You have to create your own pattern to validate it. You can try this one:



It's used for 24 hours system, like 13:28, 09:59.

X. Li
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by tushar joshi:
Hi

I am using this at server side validation.
it works fine for date format but fail to validate for time.
actually i am using this in web services to validate input data.
by using GenericValidator.

can u please help me?

Thanks in advance.



Well, the Struts validation calls:
GenericTypeValidator.validateDate(<enteredValue>, <datePattern>, false);

and I did a Test case the other day with:
GenericTypeValidator.validateDate("13:01", "HH:mm", false);
and it returned true.

I don't see why it doesn't work for you. Are you using Struts 1.2?
 
X. Li
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc is right. I just tested the code :



It's working fine. I am using Struts 1.2.
 
tushar joshi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

Thanks a lot.I had made mistake of calling method without third param.

Thanks a lot for ur examples which help me out.

bye
 
reply
    Bookmark Topic Watch Topic
  • New Topic