<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>.:Cadastro Usuario:.</title>
</head>
<f:view>
<body>
<h:form>
<h:messages layout="table" errorStyle="color: red"
infoStyle="color: green" warnStyle="color: orange"
fatalStyle="color: gray" showDetail="true" globalOnly="true" />
<h:panelGrid columns="2">
<f:facet name="header">
<h:outputText value="Dados para cadastro" />
</f:facet>
<h:outputText value="Nome:" />
<h:panelGroup>
<h:inputText id="nome" value="#{cadastroUsuarioBean.nome}" />
<h:message for="nome" />
</h:panelGroup>
<h:outputText id="email" value="E-mail:" />
<h:panelGroup>
<h:inputText size="40" maxlength="250"
value="#{cadastroUsuarioBean.email}" />
<h:message for="email" />
</h:panelGroup>
<h:outputText value="Senha:" />
<h:panelGroup>
<h:inputSecret id="senha" size="20"
value="#{cadastroUsuarioBean.senha}" />
<h:message for="senha" />
</h:panelGroup>
<h:outputText />
<h:commandButton id="cadastrar" value="Cadastrar"
actionListener="#{cadastroUsuarioBean.cadastrar}" />
</h:panelGrid>
</h:form>
</body>
</f:view>
</html>
package com.algaworks.dwjsf.visao;
import java.util.Calendar;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
public class CadastroUsuario {
private String nome;
private String email;
private String senha;
public void cadastrar(ActionEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
if (this.getNome() != null && this.getNome().length() < 10) {
context.addMessage("frm:nome",
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Nome inválido!","Digite nome completo."));
}
if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)== Calendar.THURSDAY) {
context.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Dia da semana inválido!","Você não pode cadastrar usuários na quinta."));
}
} public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
17/11/2011 14:20:35 com.sun.faces.lifecycle.RenderResponsePhase execute
INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=frm:nome[severity=(WARN 1), summary=(Nome inválido!), detail=(Digite nome completo.)]
Como resolvo isso?
