GUJ
Notícias, artigos e o maior fórum brasileiro sobre Java
home
fórum
notícias
tópicos recentes
empregos
artigos
Bem-vindo ao GUJ.
Crie seu login
, ou digite-o para logar no site.
Usuário:
Senha:
Como carregar uma list dentro de uma JSP
Índice dos Fóruns
»
Desenvolvimento Web
Autor
Mensagem
31/07/2008 16:08:37
Assunto:
Como carregar uma list dentro de uma JSP
king_of_gods
JavaTeenager
Membro desde: 28/03/2007 14:28:11
Mensagens: 185
Offline
Prezados amigos, preciso da sabedoria de vocês.
package controle; import java.util.ArrayList; import java.util.List; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import modelo.Login; /** * * @author andre.silva */ public class LoginAction { private Login login = new Login(); private List<Login> lista; public String passouAqui(){ //ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); //HttpServletRequest resp = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); System.err.println("##################### Passou aqui "+getLogin().getUsuario()+" "+getLogin().getSenha()); ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); if(login.getSenha().equals("") || login.getUsuario().equals("")){ return "error"; } lista = (List<Login>) context.getAttribute("lista"); if(lista==null) lista = new ArrayList<Login>(); lista.add(login); context.setAttribute("lista", lista); return "sucesso"; } public List<Login> carregaLista(){ ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); return (List<Login>) context.getAttribute("lista"); } public Login getLogin() { return login; } public void setLogin(Login login) { this.login = login; } public List<Login> getLista() { return lista; } public void setLista(List<Login> lista) { this.lista = lista; } }
E essa JSP:
<%@page contentType="text/html"%> <%@page 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"> <%-- This file is an entry point for JavaServer Faces application. --%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Aplicação de Teste</title> </head> <body> <f:view> <h:form id="form"> <h1 align="center"><h:outputText style="color:red" value="Aplicação de Teste" /></h1> <table> <tr> <td> <h4> <h:outputLabel value="Login:"/> </h4> </td> <td> <h:inputText id="login" title="login" value="#{loginAction.login.usuario}" /> </td> </tr> <tr> <td> <h4> <h:outputLabel value="Senha:"/> </h4> </td> <td> <h:inputSecret id="senha" title="senha" value="#{loginAction.login.senha}" /> </td> </tr> </table> <h:commandButton id="ok" title="ok" value="OK" action="#{loginAction.passouAqui}"/> <h:outputLink value="listarusuarios.jsp"> <f:verbatim>Listar Usuários</f:verbatim> </h:outputLink> </h:form> </f:view> </body> </html>
E esta outra JSP:
<%@page contentType="text/html"%> <%@page 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>JSP Page</title> </head> <body> <f:view> <h:form> <h:dataTable var="login" [color=red]value="#{loginAction.lista}"[/color] border="1"> <h:column> <f:facet name="header"> <h:outputText value="Login"/> </f:facet> <h:outputText value="#{login.usuario}"></h:outputText> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Senha"/> </f:facet> <h:outputText value="#{login.senha}"></h:outputText> </h:column> </h:dataTable> <h:outputLink value="welcomeJSF.jsp"> <f:verbatim>Voltar</f:verbatim> </h:outputLink> </h:form> </f:view> </body> </html>
Como faço para exibir a lista onde está em vermelho usando o método carregaLista().
Obrigado!
01/08/2008 13:56:07
Assunto:
Re:Como carregar uma list dentro de uma JSP
king_of_gods
JavaTeenager
Membro desde: 28/03/2007 14:28:11
Mensagens: 185
Offline
Alguém?
Índice dos Fóruns
»
Desenvolvimento Web
Ir para:
Selecione um Fórum
Notícias
Assuntos gerais (Off-topic)
MundoJ - Artigos, Notícias e Debates
Artigos e Tutoriais
Java Básico
Java Avançado
Ferramentas, Frameworks e Utilitários
Desenvolvimento Web
Interface Gráfica
Google Android e Java Micro Edition (ME)
Certificação Java
Persistência: Hibernate, JPA, JDBC e outros
Java Enterprise Edition (Java EE)
Frameworks e Bibliotecas brasileiros
RIA - Flex, JavaFX e outros
Arquitetura de Sistemas
Metodologias de Desenvolvimento e Testes de Software
JavaScript
Ruby & Ruby on Rails
Outras Linguagens
Powered by
JForum 2.1.8
©
JForum Team