cancel
Showing results for 
Search instead for 
Did you mean: 

How to do date validation in Web Dynpro java

susmita_panigrahi
Active Participant
0 Kudos

Hi

We have one requirement that One input field with date type is there.When we take Date type input field then in web dynpro Date navigater is appearing by default.Our requirement is if user enters the date manually in the input filed instead of chossing the date from the Date navigator then how we will do the following date validations manually:

a. If user is entering the date in any format then it should convert it to dd.mm.yy format.

b. How to do leap year validation?Suppose user is entering 29.02.20007 then it should display Invalid date.

c. How to do the follwing date validation:

Let's say that current running hours(Text Vie

w) on a given engine is 100, entered on 10-Jun-2008(Running hour date-Text view)).

-On 15-Jun-2008(New Running Hour Date-input field), I try to enter a value of 300 hours(New running hour-input field).

-This is impossible, because only 5x24=120 hrs has passed from the previous update.

-Hence, in this case the maximum value I can enter is 100+120=220.

Can anybody help me in solving the above 3 date validation?

Accepted Solutions (0)

Answers (5)

Answers (5)

susmita_panigrahi
Active Participant
0 Kudos

Hi

The query is solved.

srinivas_sistu
Active Contributor
0 Kudos

Hi Susmita,

For your 3 rd requirement...

Initially you will be storing the first date entered by the user right???

Say that date is D1. and user entered hours is H1.

now after some days at day D2 user again trying to enter some hours say H2. Now you have to restrict user from entering hours which are

greater than 24*D2-D1....

so now you have to get D2-D1....

For this....

long l1=youdate1.getTime(); // This will convert your Date D1 into long...

then,

Date d=new Date(System.currentTimeMillis());

long l2=d.getTime(); //which is a long value of current date...

So Now l2-l1 will give you number of days between past date and today's date...

So On Save you check for

if((l2-l1)*24<(H2-H1))

{

message("Please enter valied number of hours");

}

Hope this will help you....

Regards,

Srinivas.

}

}

Former Member
0 Kudos

Hi,

Create a simple type of type date, select basetype=date. go to representation tab, give format "dd.mm.yy"

You can use SimpleDateFormat class to format the dates.

eg:

//date to string

SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");

String str=format.format(new Date(System.currentTimeMillis()));

//string to date

SimpleDateFormat sourceFormat=new SimpleDateFormat("yyyyMMdd");

Date date=sourceFormat.parse("20080706");

Regards,

Naga

Former Member
0 Kudos

hi,

to check leap year


boolean isLeapYear(int year) {
if(year % 4 != 0)
 return false;
if(year % 100 != 0)
 return true;
if(year % 400 == 0)
 return true;
return false;
}

Regards,

Naga

Former Member
0 Kudos

Hi,

If you a inputField of date type then the framework will itself validate your manual input. I mean your first two things will be handled by the framework itself.

For the first the framework will give the error message if the format is not correct. You can use SimpleDateFormat to convert the date in dd/mm/yyyy format.

For the second scenario the framework will validate. But the message will not be appropriate and you cant change that as well.

And i didnt get your third scenario.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi,

a. If user is entering the date in any format then it should convert it to dd.mm.yy format.

For this create one symple type under Dictionaries->Local Dictionary0->Data Types->Simple type.

Rightclick and create new SimpleType.In the representation tab->format->give ur own format.

Map this simple type to your date field.

b. How to do leap year validation?Suppose user is entering 29.02.20007 then it should display Invalid date.

Check for leap year.

If the year is not leapyear then display this message.

c.I dint get the 3 rd question...

Regards,

Lavanya.G