4 Replies Latest reply on Jul 8, 2010 1:43 AM by Vijay Rajan

    Date Validation in JSF & Richfaces

    Vijay Rajan Newbie

      I m using a rich:calendar to display Date in my application
      But some how date validation isn't working properly in a particular  scenario.
      i.e it some one enters date as 05/05/2010sfc in this case it  automatically trims the extra characters in the end
      and displays date properly in next page instead of giving an error of  invalid date on same page.

      It works in other cases such as asd05/05/2010, 05sfa/05/2010, etc

      I tried using <f:convertDateTime> but it didn't help

      Can anyone please help me on this...

        • 1. Re: Date Validation in JSF & Richfaces
          Manu Gowda Newbie

          if you dnt want to enable manual entry then you can disable it by attribute enableManualInput="false"

           

          if you want the manual input then use datepattern attribute

           

          datePattern="MMM dd yyyy, HH:mm"  i.e. which ever pattern you want it.

           

          and also write the f:validator to validate the date.

          • 2. Re: Date Validation in JSF & Richfaces
            Vijay Rajan Newbie

            Thnx manu for ur reply

             

            But i have already tried this

            Currently it is required to enableManualInput, So i have to set it to true.

            I m also using a date pattern "MM/dd/yyyy" & am also using a <f:validator> tag

             

            But the problem is

            Till the value reaches my validator class it is corrected to proper date

            i.e. if i enter 05/05/2010sas my validator class recieves it as 05/05/2010

             

            I tried to trace back that at which point this value is getting corrected but in vain

            I also looked in DateTimeConverter class which gives a conversion error for

            asf05/05/2010, 05/05/2010000  but works fine for 05/05/2010sas

             

            I hope this would give u a clear idea of the problem i m facing ...

             

            I just want JSF or richfaces to give a error in case of this scenario instead of correcting the date by itselft by trimming characters at end

            • 3. Re: Date Validation in JSF & Richfaces
              Manu Gowda Newbie

              you set date pattern "MM/dd/yyyy" and you are trying to I/P  05/05/2010sas , and expecting err msg,  whatever the string you enter it take maximum MM/dd/yyyy length i.e. 12, if any I/P exceed that , that will be automatically trimmed. so in your case you are getting valid data. so my advice is to restrict the max length of your I/P.  in your case its 12, if you use date pattren MMM dd yyyy, HH:mm then its 18 etc.  hope this will help you.

              1 of 1 people found this helpful
              • 4. Re: Date Validation in JSF & Richfaces
                Vijay Rajan Newbie

                I used this tag to restrict the length to 10  characters


                < rich:calendar value="#{myBean.date}" datePattern="MM/dd/yyyy" enableManualInput="true"  inputStyle="width:80px">  

                      < f:attribute name="maxlength" value="10"/>

                < /rich:calendar>