• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to validate time field using validator framework of struts

 
tushar joshi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't look like a Java question. I'm moving it to the Struts forum.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
X. Li
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic