Prévia do material em texto
Abaixo vemos nossa página index.xhmtl. <!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://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>Estácio</title> </h:head> <h:body> <h:panelGroup rendered="#{managedBeanInscricao.formulario}"> <fieldset> <legend>Formulário de inscrição</legend> <h:form> <h:panelGrid columns="2"> <h:outputLabel value="Evento:*" for="evento" /> <h:selectOneMenu id="evento" value="#{managedBeanInscricao.idEvento}" required="true" requiredMessage="Informe o evento!"> <f:ajax event="change" listener="#{managedBeanInscricao.preparaPalestras}" execute="evento" render="palestra" /> <f:selectItems value="#{managedBeanInscricao.eventos}" /> </h:selectOneMenu> <h:outputLabel value="Palestra:*" for="palestra" /> <h:selectOneMenu id="palestra" value="#{managedBeanInscricao.idPalestra}" required="true" requiredMessage="Informe a palestra!"> <f:selectItems value="#{managedBeanInscricao.palestras}" /> </h:selectOneMenu> <h:outputLabel value="CPF:*" for="cpf" /> <h:inputText id="cpf" value="#{managedBeanInscricao.inscricao.participante.cpf}" required="true" requiredMessage="Informe o CPF!" /> <h:outputLabel value="Nome:*" for="nome" /> <h:inputText id="nome" value="#{managedBeanInscricao.inscricao.participante.nome}" required="true" requiredMessage="Informe o nome!" /> <h:outputLabel value="Email:*" for="email" /> <h:inputText id="email" value="#{managedBeanInscricao.inscricao.participante.email}" required="true" requiredMessage="Informe a email!" /> <h:outputLabel value="Curso:" for="curso" /> <h:inputText id="curso" value="#{managedBeanInscricao.inscricao.participante.curso}" /> <h:outputLabel value="Instituição de Ensino:" for="instituicao" /> <h:inputText id="instituicao" value="#{managedBeanInscricao.inscricao.participante.instituicao}" /> <h:outputLabel value="Telefone:*" for="telefone" /> <h:inputText id="telefone" value="#{managedBeanInscricao.inscricao.participante.telefone}" required="true" requiredMessage="Informe o telefone!" /> <h:outputLabel value="Endereço:*" for="endereco" /> <h:inputText id="endereco" value="#{managedBeanInscricao.inscricao.participante.endereco}" required="true" requiredMessage="Informe o endereço" /> <h:outputLabel value="Bairro:*" for="bairro" /> <h:inputText id="bairro" value="#{managedBeanInscricao.inscricao.participante.bairro}" required="true" requiredMessage="Informe o bairro!" /> <h:outputLabel value="Cidade:*" for="municipio" /> <h:inputText id="municipio" value="#{managedBeanInscricao.inscricao.participante.municipio}" required="true" requiredMessage="Informe a cidade" /> <h:outputLabel value="UF:*" for="uf" required="true" requiredMessage="Informe o estado!" /> <h:selectOneMenu id="uf" value="#{managedBeanInscricao.inscricao.participante.uf}"> <f:selectItem itemLabel="Rio Grande do Norte" itemValue="RN" /> <f:selectItem itemLabel="Rio de Janeiro" itemValue="RJ" /> <f:selectItem itemLabel="São Paulo" itemValue="SP" /> </h:selectOneMenu> <h:outputLabel value="CEP:" for="cep" /> <h:inputText id="cep" value="#{managedBeanInscricao.inscricao.participante.cep}" /> <h:commandButton value="Avançar" action="#{managedBeanInscricao.realizarIncrcao}" /> </h:panelGrid> </h:form> </fieldset> </h:panelGroup> <h:messages /> </h:body> </html> Apesar de funcional nossa página está mal estilizada, para melhorar sem tratamento estético, utilizaremos uma biblioteca de componentes adicional que será PrimeFaces. Abaixo temos nossa mesma página, contudo utilizando os componentes disponibilizados pele PrimeFaces e não pela implementação padrão. <!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://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" > <h:head> <title>Estácio</title> </h:head> <h:body> <h:panelGroup rendered="#{managedBeanInscricao.formulario}"> <p:panel header="Formulário de inscrição"> <h:form> <h:panelGrid columns="2"> <h:outputLabel value="Evento:*" for="evento" /> <h:selectOneMenu id="evento" value="#{managedBeanInscricao.idEvento}" required="true" requiredMessage="Informe o evento!"> <f:ajax event="change" listener="#{managedBeanInscricao.preparaPalestras}" execute="evento" render="palestra" /> <f:selectItems value="#{managedBeanInscricao.eventos}"/> </h:selectOneMenu> <h:outputLabel value="Palestra:*" for="palestra" /> <h:selectOneMenu id="palestra" value="#{managedBeanInscricao.idPalestra}" required="true" requiredMessage="Informe a palestra!"> <f:selectItems value="#{managedBeanInscricao.palestras}"/> </h:selectOneMenu> <h:outputLabel value="CPF:*" for="cpf" /> <p:inputMask mask="999.999.999-99" id="cpf" value="#{managedBeanInscricao.inscricao.participante.cpf}" required="true" requiredMessage="Informe o CPF!"/> <h:outputLabel value="Nome:*" for="nome" /> <p:inputText id="nome" value="#{managedBeanInscricao.inscricao.participante.nome}" required="true" requiredMessage="Informe o nome!"/> <h:outputLabel value="Email:*" for="email" /> <p:inputText id="email" value="#{managedBeanInscricao.inscricao.participante.email}" required="true" requiredMessage="Informe a email!"/> <h:outputLabel value="Curso:" for="curso" /> <p:inputText id="curso" value="#{managedBeanInscricao.inscricao.participante.curso}" /> <h:outputLabel value="Instituição de Ensino:" for="instituicao" /> <p:inputText id="instituicao" value="#{managedBeanInscricao.inscricao.participante.instituicao}" /> <h:outputLabel value="Telefone:*" for="telefone" /> <p:inputMask mask="(99) 9999-9999" id="telefone" value="#{managedBeanInscricao.inscricao.participante.telefone}" required="true" requiredMessage="Informe o telefone!"/> <h:outputLabel value="Endereço:*" for="endereco" /> <p:inputText id="endereco" value="#{managedBeanInscricao.inscricao.participante.endereco}" required="true" requiredMessage="Informe o endereço"/> <h:outputLabel value="Bairro:*" for="bairro" /> <p:inputText id="bairro" value="#{managedBeanInscricao.inscricao.participante.bairro}" required="true" requiredMessage="Informe o bairro!"/> <h:outputLabel value="Cidade:*" for="municipio" /> <p:inputText id="municipio" value="#{managedBeanInscricao.inscricao.participante.municipio}" required="true" requiredMessage="Informe a cidade"/> <h:outputLabel value="UF:*" for="uf" required="true" requiredMessage="Informe o estado!"/> <h:selectOneMenu id="uf" value="#{managedBeanInscricao.inscricao.participante.uf}"> <f:selectItem itemLabel="Rio Grande do Norte" itemValue="RN" /> <f:selectItem itemLabel="Rio de Janeiro" itemValue="RJ" /> <f:selectItem itemLabel="São Paulo" itemValue="SP" /> </h:selectOneMenu> <h:outputLabel value="CEP:" for="cep" /> <p:inputMask mask="99.999-999"id="cep" value="#{managedBeanInscricao.inscricao.participante.cep}" /> <p:commandButton value="Avançar" ajax="false" action="#{managedBeanInscricao.realizarIncrcao}" update="messages" /> </h:panelGrid> </h:form> </p:panel> </h:panelGroup> <p:messages id="messages" /> </h:body> </html> Para finalizar, criaremos uma página resultado.xhtml que contará somente com um componente <p:messages id="messages" /> que apenas apresentará as mensagens criadas nos ManagedBeanInscricoes. resultado.xhtml <!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://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head> <title>Estácio</title> </h:head> <body> <p:messages /> </body> </html>