Created
June 4, 2018 14:37
-
-
Save nosrednawall/ee27eb188b9ba34a15aabed0a6bceaa8 to your computer and use it in GitHub Desktop.
Restrição de idade por enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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}" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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