Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FacesConverter("projetoConverter")
- public class ProjetoConverter implements Converter {
- @Override
- public Object getAsObject(FacesContext faces, UIComponent component, String valor) {
- try {
- Long codigo = Long.parseLong(valor);
- ProjetoDAO projetoDAO = new ProjetoDAO();
- Projeto projeto = projetoDAO.buscarPorCodigo(codigo);
- return projeto;
- } catch (RuntimeException ex) {
- return null;
- }
- }
- @Override
- public String getAsString(FacesContext faces, UIComponent component, Object objeto) {
- if (!objeto.equals("")) {
- System.out.println(objeto);
- try {
- Projeto projeto = (Projeto) objeto;
- Long codigo = projeto.getPro_codigo();
- System.out.println(codigo);
- return codigo.toString();
- } catch (RuntimeException ex) {
- return null;
- }
- }
- return "";
- }
- }
- @FacesConverter("empresaConverter")
- public class EmpresaConverter implements Converter {
- @Override
- public Object getAsObject(FacesContext faces, UIComponent component, String valor) {
- try {
- Long codigo = Long.parseLong(valor);
- EmpresaDAO empresaDAO = new EmpresaDAO();
- Empresa empresa = empresaDAO.buscarPorCodigo(codigo);
- return empresa;
- } catch (RuntimeException ex) {
- return null;
- }
- }
- @Override
- public String getAsString(FacesContext faces, UIComponent component, Object objeto) {
- try {
- Empresa empresa = (Empresa) objeto;
- Long codigo = empresa.getCodigo();
- System.out.println(codigo.toString());
- return codigo.toString();
- } catch (RuntimeException ex) {
- return null;
- }
- }
- }
- @SuppressWarnings("unchecked")
- public List<Projeto> listarProjeto() {
- // Cria uma nova sess�o
- Session sessao = HibernateUtil.getSessionFactory().openSession();
- List<Projeto> projeto = null;
- try {
- // Executa query de consulta
- Query consulta = sessao.getNamedQuery("Projeto.listarProjeto");
- projeto = consulta.list();
- } catch (RuntimeException ex) {
- throw ex;
- } finally {
- // Fecha a sess�o
- sessao.close();
- }
- return projeto;
- }
- public List<SelectItem> getImediatoselect() {
- if(Imediatoselect == null){
- Imediatoselect = new ArrayList<SelectItem>();
- ProjetoDAO projetoDAO = new ProjetoDAO();
- List<Projeto> listaProjeto = projetoDAO.listarProjeto();
- if(listaProjeto != null && !listaProjeto.isEmpty()){
- SelectItem item;
- for (Projeto projetoLista : listaProjeto) {
- item = new SelectItem(projetoLista, projetoLista.getPro_superiorImediato());
- Imediatoselect.add(item);
- }
- }
- }
- return Imediatoselect;
- }
- @SuppressWarnings("unchecked")
- public List<Empresa> listarEmpresa() {
- Session sessao = HibernateUtil.getSessionFactory().openSession();
- List<Empresa> empresa = null;
- try {
- // Executa query de consulta
- Query consulta = sessao.getNamedQuery("Empresa.listarEmpresa");
- empresa = consulta.list();
- } catch (RuntimeException ex) {
- throw ex;
- } finally {
- // Fecha a sess�o
- sessao.close();
- }
- return empresa;
- }
- public List<SelectItem> getDepartamentoselect() {
- if (Departamentoselect == null) {
- Departamentoselect = new ArrayList<SelectItem>();
- EmpresaDAO empresaDAO = new EmpresaDAO();
- List<Empresa> listaEmpresa = empresaDAO.listarEmpresa();
- if (listaEmpresa != null && !listaEmpresa.isEmpty()) {
- SelectItem item;
- for (Empresa empresaLista : listaEmpresa) {
- item = new SelectItem(empresaLista, empresaLista.getDepartamento());
- Departamentoselect.add(item);
- }
- }
- }
- return Departamentoselect;
- }
- <p:outputLabel class="lt" value="Projeto:" />
- <p:selectOneMenu value="#{usuarioBean.projeto.pro_projeto}"
- converter="projetoConverter">
- <f:selectItem itemLabel="Selecione o projeto" itemValue="" />
- <f:selectItems value="#{projetoBean.projetoselect}" />
- </p:selectOneMenu>
- <p:outputLabel class="lt" value="Superior Imediato:" />
- <p:selectOneMenu value="#{projetoBean.projetoSelecionado}">
- <f:selectItem itemLabel="Selecione o superior" itemValue="" />
- <f:selectItems value="#{projetoBean.imediatoselect}" />
- </p:selectOneMenu>
- converter="#{projetoConverter}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement