Advertisement
Guest User

Untitled

a guest
May 5th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. @FacesConverter("projetoConverter")
  2. public class ProjetoConverter implements Converter {
  3.  
  4. @Override
  5. public Object getAsObject(FacesContext faces, UIComponent component, String valor) {
  6.  
  7. try {
  8. Long codigo = Long.parseLong(valor);
  9. ProjetoDAO projetoDAO = new ProjetoDAO();
  10. Projeto projeto = projetoDAO.buscarPorCodigo(codigo);
  11. return projeto;
  12. } catch (RuntimeException ex) {
  13. return null;
  14. }
  15. }
  16.  
  17. @Override
  18. public String getAsString(FacesContext faces, UIComponent component, Object objeto) {
  19. if (!objeto.equals("")) {
  20. System.out.println(objeto);
  21. try {
  22. Projeto projeto = (Projeto) objeto;
  23. Long codigo = projeto.getPro_codigo();
  24. System.out.println(codigo);
  25. return codigo.toString();
  26. } catch (RuntimeException ex) {
  27. return null;
  28. }
  29. }
  30. return "";
  31. }
  32.  
  33. }
  34.  
  35. @FacesConverter("empresaConverter")
  36. public class EmpresaConverter implements Converter {
  37.  
  38. @Override
  39. public Object getAsObject(FacesContext faces, UIComponent component, String valor) {
  40.  
  41. try {
  42. Long codigo = Long.parseLong(valor);
  43. EmpresaDAO empresaDAO = new EmpresaDAO();
  44. Empresa empresa = empresaDAO.buscarPorCodigo(codigo);
  45.  
  46. return empresa;
  47. } catch (RuntimeException ex) {
  48. return null;
  49. }
  50.  
  51. }
  52.  
  53. @Override
  54. public String getAsString(FacesContext faces, UIComponent component, Object objeto) {
  55. try {
  56. Empresa empresa = (Empresa) objeto;
  57. Long codigo = empresa.getCodigo();
  58. System.out.println(codigo.toString());
  59.  
  60. return codigo.toString();
  61. } catch (RuntimeException ex) {
  62. return null;
  63. }
  64. }
  65.  
  66. }
  67.  
  68. @SuppressWarnings("unchecked")
  69. public List<Projeto> listarProjeto() {
  70. // Cria uma nova sess�o
  71. Session sessao = HibernateUtil.getSessionFactory().openSession();
  72. List<Projeto> projeto = null;
  73.  
  74. try {
  75. // Executa query de consulta
  76. Query consulta = sessao.getNamedQuery("Projeto.listarProjeto");
  77. projeto = consulta.list();
  78. } catch (RuntimeException ex) {
  79. throw ex;
  80. } finally {
  81. // Fecha a sess�o
  82. sessao.close();
  83. }
  84. return projeto;
  85. }
  86.  
  87. public List<SelectItem> getImediatoselect() {
  88.  
  89. if(Imediatoselect == null){
  90. Imediatoselect = new ArrayList<SelectItem>();
  91. ProjetoDAO projetoDAO = new ProjetoDAO();
  92. List<Projeto> listaProjeto = projetoDAO.listarProjeto();
  93.  
  94. if(listaProjeto != null && !listaProjeto.isEmpty()){
  95. SelectItem item;
  96. for (Projeto projetoLista : listaProjeto) {
  97. item = new SelectItem(projetoLista, projetoLista.getPro_superiorImediato());
  98. Imediatoselect.add(item);
  99. }
  100. }
  101. }
  102.  
  103. return Imediatoselect;
  104. }
  105.  
  106. @SuppressWarnings("unchecked")
  107. public List<Empresa> listarEmpresa() {
  108. Session sessao = HibernateUtil.getSessionFactory().openSession();
  109. List<Empresa> empresa = null;
  110.  
  111. try {
  112. // Executa query de consulta
  113. Query consulta = sessao.getNamedQuery("Empresa.listarEmpresa");
  114. empresa = consulta.list();
  115. } catch (RuntimeException ex) {
  116. throw ex;
  117. } finally {
  118. // Fecha a sess�o
  119. sessao.close();
  120. }
  121. return empresa;
  122. }
  123.  
  124. public List<SelectItem> getDepartamentoselect() {
  125.  
  126. if (Departamentoselect == null) {
  127. Departamentoselect = new ArrayList<SelectItem>();
  128. EmpresaDAO empresaDAO = new EmpresaDAO();
  129. List<Empresa> listaEmpresa = empresaDAO.listarEmpresa();
  130.  
  131. if (listaEmpresa != null && !listaEmpresa.isEmpty()) {
  132. SelectItem item;
  133. for (Empresa empresaLista : listaEmpresa) {
  134. item = new SelectItem(empresaLista, empresaLista.getDepartamento());
  135. Departamentoselect.add(item);
  136. }
  137. }
  138. }
  139.  
  140. return Departamentoselect;
  141. }
  142.  
  143. <p:outputLabel class="lt" value="Projeto:" />
  144. <p:selectOneMenu value="#{usuarioBean.projeto.pro_projeto}"
  145. converter="projetoConverter">
  146. <f:selectItem itemLabel="Selecione o projeto" itemValue="" />
  147. <f:selectItems value="#{projetoBean.projetoselect}" />
  148. </p:selectOneMenu>
  149. <p:outputLabel class="lt" value="Superior Imediato:" />
  150. <p:selectOneMenu value="#{projetoBean.projetoSelecionado}">
  151. <f:selectItem itemLabel="Selecione o superior" itemValue="" />
  152. <f:selectItems value="#{projetoBean.imediatoselect}" />
  153. </p:selectOneMenu>
  154.  
  155. converter="#{projetoConverter}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement