Good day team,
I have two fields in my editor screen, first one is a date field (DOB) and the second is an Enum filed (age group). When a user enters the date of birth, it calculates to which age group the user belongs and based on that set the age group automatically.
My challenge is changing the value of the age group right after the user is done entering the date, secondly if the user enters a date in the future is should clear the field.
Here is my code…
@Override
public void init(Map<String, Object> params) {
// TODO Auto-generated method stub
super.init(params);
personDS.addItemPropertyChangeListener(e -> updatefield(e.getPrevValue()));
}
private void updatefield(Object previuosValue)
{
Calendar temp = Calendar.getInstance();
Date today = temp.getTime();
if(personDS.getItem().getDate_of_Birth().after(today))
{
personDS.getItem().setDate_of_Birth(null);
showNotification(" Date of Birth cannot be in future ", NotificationType.TRAY);
}
else if (personDS.getItem().getDate_of_Birth().equals(today))
{
personDS.getItem().setDate_of_Birth(null);
showNotification(" Date of birth provided is invalid ", NotificationType.TRAY);
}
else
{
//DOB
Calendar cal = Calendar.getInstance();
cal.setTime(personDS.getItem().getDate_of_Birth());
int dob = cal.get(Calendar.YEAR);//gets the year
//Current year
Calendar cal1 = Calendar.getInstance();
int currentyear = cal1.get(Calendar.YEAR); //gets the year
//age of passager
int age = currentyear - dob;
if(age > 21)
{
personDS.getItem().setAge_Group(Age.Child);
//ticketDs.
}
else if(age < 21)
{
personDS.getItem().setAge_Group(Age.Adult);
}
}
}
How do i go about to refresh such that the changes are effective just after entering the date
Thanks,