1
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, display the "ok" message. 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;
}
}
jsp? Can you add as is your code?
– user28595
Poisé Marcos, checking your doubt I figured it would be jsp too.
– Flávio Granato
are 2
<p:calendar>
one for dtInitial and one for dtFinal?– Henrique Santiago
if it is, this component of the first faces works with the class
Date
of the java.util package.– Henrique Santiago