k3ati

Untitled

Mar 26th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml"
  6. xmlns:ui="http://java.sun.com/jsf/facelets"
  7. xmlns:h="http://java.sun.com/jsf/html"
  8. xmlns:f="http://java.sun.com/jsf/core">
  9.  
  10.  
  11. <h:dataTable value="#{controleCliente.clientes}" var="cliente" border="1">
  12. <h:column>
  13. <f:facet name="header">ID</f:facet>
  14. #{cliente.id}
  15. </h:column>
  16. <h:column>
  17. <f:facet name="header">Name</f:facet>
  18. #{cliente.nome}
  19. </h:column>
  20. <h:column>
  21. <f:facet name="header">Idade</f:facet>
  22. #{cliente.idade}
  23. </h:column>
  24.  
  25. </h:dataTable>
  26.  
  27. </html>
  28.  
  29.  
  30. package com.exemplo.controle;
  31.  
  32. import java.util.List;
  33.  
  34. import javax.faces.bean.ManagedBean;
  35. import javax.faces.bean.SessionScoped;
  36. import com.exemplo.entidade.Cliente;
  37. import com.exemplo.repositorio.RepositorioCliente;
  38.  
  39.  
  40.  
  41. @ManagedBean
  42. @SessionScoped
  43. public class ControleCliente {
  44.  
  45. Cliente cliente;
  46. List<Cliente> clientes;
  47. RepositorioCliente repositorioCliente;
  48.  
  49. public ControleCliente(){
  50. repositorioCliente = new RepositorioCliente();
  51. cliente = new Cliente();
  52. }
  53.  
  54. public String salvar(){
  55. repositorioCliente.salvar(cliente);
  56. return "index";
  57. }
  58.  
  59. public Cliente getCliente() {
  60. return cliente;
  61. }
  62.  
  63. public void setCliente(Cliente cliente) {
  64. this.cliente = cliente;
  65. }
  66.  
  67. public List<Cliente> getClientes() {
  68. clientes = repositorioCliente.listarTodos();
  69. return clientes;
  70. }
  71.  
  72. public void setClientes(List<Cliente> clientes) {
  73. this.clientes = clientes;
  74. }
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  84. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  85.  
  86. <html xmlns="http://www.w3.org/1999/xhtml"
  87. xmlns:ui="http://java.sun.com/jsf/facelets"
  88. xmlns:h="http://java.sun.com/jsf/html"
  89. xmlns:f="http://java.sun.com/jsf/core">
  90.  
  91. <h:form>
  92. <h:outputText value="Nome: " />
  93. <h:inputText value="#{controleCliente.cliente.nome}"/><br />
  94. <h:outputText value="Idade: "/>
  95. <h:inputText value="#{controleCliente.cliente.idade}"/>
  96. <h:commandButton action="#{controleCliente.salvar}"/>
  97. </h:outputText>
  98. </h:form>
  99.  
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment