In my component p:calendar
there are two date ranges dtInicial
and dtFinal
in the managed bean I need to compare only the years and validate. If it is the same year, show the message "ok". Otherwise, "different years."
private int getYear(Date date) {
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
return calendar.get(Calendar.YEAR);
}
boolean hasInterval = sourceReq.getDtInicial() != null
&& sourceReq.getDtInicial() != null;
if (hasInterval){
int dtIni = getYear(sourceReq.getDtInicial());
int dtFin = getYear(sourceReq.getDtFinal());
if (dtIni != dtFin){
showErrorMessage("Favor informar o mesmo Ano para Pesquisa.", true);
return false;
}
}