Skip to content

Instantly share code, notes, and snippets.

View nosrednawall's full-sized avatar

Anderson José de Souza Inácio nosrednawall

View GitHub Profile
@nosrednawall
nosrednawall / metodoStringToEnum.java
Created July 9, 2018 12:23
Fazendo o parse de String para enum diretamente da classe entity
public void setPaisRecebendoEmString(String paisEmTexto) {
PaisesEnum[] paises = PaisesEnum.values();
for (PaisesEnum paisesEnum : paises) {
if (paisEmTexto.equalsIgnoreCase(paisesEnum.toString())) {
this.pais = paisesEnum;
}
}
}
public void setEstadoRecebendoEmString(String estadoEmTexto) {
@nosrednawall
nosrednawall / enumComString.java
Last active June 21, 2018 12:33
Enum com string
MACACO_AND_GURILA("Macaco","Gurila"),
JACA_AND_ESCADA("Escada","Jaca");
private String tipoUm, tipoDois;
private TiposEnum(String tipoUm, String tipoDois) {
this.tipoUm = tipoUm;
this.tipoDois = tipoDois;
}
@nosrednawall
nosrednawall / Bean.java
Created June 19, 2018 13:30
renderiza telas xhtml primefaces
@ManagedBean(name="redBean")
@SessionScoped
public class Bean {
private Integer opcao;
private Boolean isRederiza = false;
public Boolean getIsRederiza() {
return isRederiza;
}
public Integer getOpcao() {
return opcao;
@nosrednawall
nosrednawall / minhaTabelaAtualiza.xhtml
Last active June 18, 2018 12:39
Atualizar campos com primefaces
<h:form>
<!-- aqui fica a declaração da tabela -->
<p:dataTable id="tabela" value="#{meuBean.pessoas}"
var="pessoa"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
paginator="true" rows="10" style="margin-bottom:20px"
rowStyleClass="#{pessoa.status == 'INATIVO' ? 'inativo-row' : null}"
liveResize="true" emptyMessage="Nenhum Registro Encontrado">
<!-- aqui fica o select com os status da tebela -->
<f:facet name="header">
@nosrednawall
nosrednawall / arquivo.xhtml
Created June 5, 2018 17:14
Carregando mensagem de messages.properties
<f:loadBundle basename="messages" var="msgs" />
<p:outputLabel value="Nome" for="nome" />
<p:inputText id="nome" value="#{seuBean.entidade.nome}"
required="true" requiredMessage="#{msg.nomeBranco}">
<f:ajax event="blur" render="messageNome" />
<p:message for="nome" id="messageNome" />
</p:inputText>
@nosrednawall
nosrednawall / _template.xhtml
Last active June 5, 2018 17:11
Template xhtml para jsf
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
@nosrednawall
nosrednawall / BaseBean.java
Created June 4, 2018 14:37
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) + "/"
@nosrednawall
nosrednawall / cpfCnpj.xhtml
Last active June 4, 2018 13:53
Validador regex para cpf e cnpj, apenas para quantidade de caracteres
<p:outputLabel value="Cpf/CNPJ " for="cpf" />
<p:inputText id="cpf" value="#{seuBean.entitade.cpfCnpj}"
maxlength="20" required="true"
requiredMessage="Campo cpf não pode estar em branco"
validatorMessage="CPF inválido">
<f:passThroughAttribute name="placeholder" value="Informe o seu CPF ou CNPJ" />
<f:validateRegex
pattern="([0-9]{2}[\.]?[0-9]{3}[\.]?[0-9]{3}[\/]?[0-9]{4}[-]?[0-9]{2})|([0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2})" />
<f:ajax event="blur" render="messageCpf" />
@nosrednawall
nosrednawall / password.xhtml
Last active June 4, 2018 13:27
password regex validator jsf
<p:outputLabel value="Senha" for="senha" />
<p:password id="senha" value="#{seuBean.entidade.senha}"
feedback="true"
required="true"
requiredMessage="Campo senha não pode estar em branco"
validatorMessage="Senha inválida"
>
<f:attribute name="type" value="password" />
<f:passThroughAttribute name="placeholder" value="No mímino 6 e no máximo 20 caracteres" />
@nosrednawall
nosrednawall / _template.xhtml
Created June 4, 2018 12:53
locate pt_BR primefaces
<h:head>
<h:outputScript library="js" name="locale-primefaces.js"/>
</h:head>
<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"