aspose file tools*
The moose likes Struts and the fly likes How to validate time field using validator framework of struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to validate time field using validator framework of struts" Watch "How to validate time field using validator framework of struts" New topic
Author

How to validate time field using validator framework of struts

tushar joshi
Greenhorn

Joined: Feb 08, 2005
Posts: 10
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

Joined: Jul 22, 2000
Posts: 9053
    
  12
Doesn't look like a Java question. I'm moving it to the Struts forum.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Works fine for me. Are you using client-side(javascript) validation or server-side validation?


A good workman is known by his tools.
tushar joshi
Greenhorn

Joined: Feb 08, 2005
Posts: 10
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

Joined: Jan 31, 2004
Posts: 61
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

Joined: Feb 05, 2003
Posts: 4727

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

Joined: Jan 31, 2004
Posts: 61
Marc is right. I just tested the code :



It's working fine. I am using Struts 1.2.
tushar joshi
Greenhorn

Joined: Feb 08, 2005
Posts: 10
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to validate time field using validator framework of struts