Skip to content

Instantly share code, notes, and snippets.

@nosrednawall
Created June 4, 2018 14:37
Show Gist options
  • Save nosrednawall/ee27eb188b9ba34a15aabed0a6bceaa8 to your computer and use it in GitHub Desktop.
Save nosrednawall/ee27eb188b9ba34a15aabed0a6bceaa8 to your computer and use it in GitHub Desktop.
Restrição de idade por enum
public abstract class BaseBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Date getMinAge() {
Calendar currentDate = Calendar.getInstance();
currentDate.add(Calendar.YEAR, - DatasLimiteEnum.IdadeMinima.getIdadeNumeral());
logger.info("Min Age: " + currentDate.get(Calendar.MONTH) + "/" + currentDate.get(Calendar.DATE) + "/"
+ currentDate.get(Calendar.YEAR));
return currentDate.getTime();
}
public Date getMaxAge() {
Calendar currentDate = Calendar.getInstance();
currentDate.add(Calendar.YEAR, - DatasLimiteEnum.IdadeMaxima.getIdadeNumeral());
logger.info("Max Age: " + currentDate.get(Calendar.MONTH) + "/" + currentDate.get(Calendar.DATE) + "/"
+ currentDate.get(Calendar.YEAR));
return currentDate.getTime();
}
}
<p:outputLabel value="Data Nascimento" for="dataNacimento" />
<p:calendar id="dataNacimento"
value="#{seuBean.entidade.dataNascimento}" showOn="button"
pattern="dd-MM-yyyy" navigator="true" locale="pt_BR"
mindate="#{seuBean.maxAge}"
maxdate="#{seuBean.minAge}" />
public enum DatasLimiteEnum {
IdadeMaxima(120), IdadeMinima(14);
private final Integer idadeNumeral;
private DatasLimiteEnum(Integer idadeNumeral) {
this.idadeNumeral = idadeNumeral;
}
public Integer getIdadeNumeral() {
return this.idadeNumeral;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment