You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Whitmire, Tracy Carroll" <tc...@sandia.gov> on 2006/12/01 20:08:54 UTC

inputCalendar validator

Hi,

I'm using t:inputCalendar and have a question I'm sure someone has
already addressed.  But a google search was futile.

If a user decides to enter the input in manually .... What's the best
way to validate this input?

I have a user who loves to enter the date as MM/dd/YY ignoring the help
text

But the expected is MM/dd/yyyy

So when he enters 12/01/06 ....

It gets entered into the database as Dec, 01, 0006

Thanks for your help,

tc

Re: inputCalendar validator

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
>
> I have a user who loves to enter the date as MM/dd/YY ignoring the
> help text
>
> But the expected is MM/dd/yyyy
>
> So when he enters 12/01/06 ….
>
Might not be much of help, but I implemented a rather complicated
converter ... well not that complicated, just uses tons of simple date
formats ... to allow the user to enter virtually any date. e.g.
mm/dd/yyyy, mm/dd/yy, mm/dd or just dd for the first two cases I use the
fact that you can have a DateFormat m/d/y and java is smart enough to
parse it right.

        SimpleDateFormat sdf = new SimpleDateFormat("M/d/y", Locale.US);
        System.err.println(sdf.parse("12/01/06"));
        System.err.println(sdf.parse("12/01/2006"));

With some tricky string operations you can create the patterns in a
locale sensitive way.

Ciao,
Mario


Re: inputCalendar validator

Posted by Holger Prause <h....@gmx.net>.
Whitmire, Tracy Carroll schrieb:
>
> Hi,
>
> I'm using t:inputCalendar and have a question I'm sure someone has 
> already addressed. But a google search was futile.
>
> If a user decides to enter the input in manually …. What's the best 
> way to validate this input?
>
> I have a user who loves to enter the date as MM/dd/YY ignoring the 
> help text
>
> But the expected is MM/dd/yyyy
>
> So when he enters 12/01/06 ….
>
> It gets entered into the database as Dec, 01, 0006
>
> Thanks for your help,
>
> tc
>
I use the following code to do that (just write a validator like u are 
used to it in jsf)

<t:inputCalendar id="birthDate"
value="#{member.birthDate}"
renderAsPopup="true"
popupTodayString="#{messages['popup_today_string']}"
popupWeekString="#{messages['popup_week_string']}"
popupDateFormat="dd.MM.yyyy"
helpText="DD.MM.YYYY"
required="true"
validator="#{validators.birthDateValidator.validate}"/>

where validators is a bean and returns a new Validator Object (u can 
play around a bit and register the validator in faces-config.xml but i 
choosed this approach).
Just write a validator like in jsf.

public class BirthDateValidator implements Validator {


public void validate(FacesContext fc, UIComponent uic, Object o) {
//do validation here
}

}


thats it, i was suprised it works like i "expected"




Re: inputCalendar validator

Posted by Jeff Bischoff <jb...@klkurz.com>.
Yaron,

I think you did not quite understand his scenario. The user is entering 
"MM/dd/YY" format (by hand, not clicking) instead of "MM/dd/yyyy". A 
validator could easily detect that the year entered is too short, and 
send a message stating such back to the user.

Now in the case of MM/dd being confused with dd/MM.... there, you would 
really be in trouble. :)

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Yaron Spektor wrote:
> Don't you sometimes wish you could replace some of your users :->
> 
>  
> 
> But seriously, your question does not seem to be a JSF related question,
> if the user clicks a valid date you can not check (as far as I know)
> what he thought when he entered it.
> 
> My workaround would be to switch the input to comboBox, then you don't
> need any validation. In order to solve your problem, present the month
> as names "Jan", "Feb" etc. while leaving the dates as numbers, that
> should do the trick.
> 
>  
> 
> Good luck :->
> 
> ________________________________
> 
> From: Whitmire, Tracy Carroll [mailto:tcwhitm@sandia.gov] 
> Sent: Friday, December 01, 2006 2:09 PM
> To: users@myfaces.apache.org
> Subject: inputCalendar validator
> 
>  
> 
> Hi, 
> 
> I'm using t:inputCalendar and have a question I'm sure someone has
> already addressed.  But a google search was futile. 
> 
> If a user decides to enter the input in manually .... What's the best
> way to validate this input? 
> 
> I have a user who loves to enter the date as MM/dd/YY ignoring the help
> text 
> 
> But the expected is MM/dd/yyyy 
> 
> So when he enters 12/01/06 .... 
> 
> It gets entered into the database as Dec, 01, 0006 
> 
> Thanks for your help, 
> 
> tc 
> 
> 



RE: inputCalendar validator

Posted by Yaron Spektor <ya...@b6systems.com>.
Don't you sometimes wish you could replace some of your users :->

 

But seriously, your question does not seem to be a JSF related question,
if the user clicks a valid date you can not check (as far as I know)
what he thought when he entered it.

My workaround would be to switch the input to comboBox, then you don't
need any validation. In order to solve your problem, present the month
as names "Jan", "Feb" etc. while leaving the dates as numbers, that
should do the trick.

 

Good luck :->

________________________________

From: Whitmire, Tracy Carroll [mailto:tcwhitm@sandia.gov] 
Sent: Friday, December 01, 2006 2:09 PM
To: users@myfaces.apache.org
Subject: inputCalendar validator

 

Hi, 

I'm using t:inputCalendar and have a question I'm sure someone has
already addressed.  But a google search was futile. 

If a user decides to enter the input in manually .... What's the best
way to validate this input? 

I have a user who loves to enter the date as MM/dd/YY ignoring the help
text 

But the expected is MM/dd/yyyy 

So when he enters 12/01/06 .... 

It gets entered into the database as Dec, 01, 0006 

Thanks for your help, 

tc