[Resolvido] selectOneMenu + icefaces

4 respostas
F

Alguem ae me da uma luz ou um dica de como popular meu ice:selectOneMenu?

Estou trabalhando com estrutura de dao, daoimpl, service(interface) , serviceimpl, dto e component.

Alguem por acaso me da uma luz, ou um exemplo?
Não sei o que fazer na minha Bean, eu sei que tenho que usar minha interface (Service), mas não sei como, já tentei de várias maneiras.

DAO

package br.com.model.cadastro.dao;

import java.util.List;

import br.com.model.cadastro.dto.CadastroProcDTO;
import br.com.model.comum.exception.DAOException;

public interface CadastroProcDAO {
	public void incluir(CadastroProcDTO cadastroProcDTO) throws DAOException;
	public List pesquisar(CadastroProcDTO cadastroProcDTO) throws DAOException;
}
DAO.impl
package br.com.model.cadastro.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.naming.NamingException;

import br.com.model.cadastro.dao.CadastroProcDAO;
import br.com.model.cadastro.dto.CadastroProcDTO;
import br.com.model.comum.exception.DAOException;
import br.com.model.comum.util.ServiceLocator;

public class CadastroProcDAOImpl  implements CadastroProcDAO{
	public void incluir(CadastroProcDTO cadastroProcDTO) throws DAOException {
		try {
			String sql = "INSERT INTO D2_PROC P" +
						 "\n (P.IDPROC, P.NPROC)" +
						 "\n values (?,?)";
			Connection conn = ServiceLocator.getServiceLocator().getDataSource().getConnection();
			PreparedStatement ps = conn.prepareStatement(sql);
			
			ps.setString(1, cadastroProcDTO.getId());
			ps.setString(2, cadastroProcDTO.getNProc());
			ResultSet rs = ps.executeQuery();
			
			rs.next();
			
		}
		catch (SQLException e){
			throw new DAOException(e.getMessage());
		}
		catch (NamingException e){
			throw new DAOException(e.getMessage());
		}
	}
	public List<CadastroProcDTO> pesquisar(CadastroProcDTO cadastroProcDTO) throws DAOException{
		try {
			String sql = "SELECT * from D2_Proc";
			
			Connection conn = ServiceLocator.getServiceLocator().getDataSource().getConnection();
			PreparedStatement ps = conn.prepareStatement(sql);
			
			ResultSet rs = ps.executeQuery();
			ArrayList<CadastroProcDTO> result = new ArrayList<CadastroProcDTO>();
			while (rs.next()) {
				CadastroProcDTO cadastroProc = new CadastroProcDTO();
				
				cadastroProc.setId(rs.getString("IDPROC"));
				cadastroProc.setNProc(rs.getString("NPROC"));
				
				result.add(cadastroProc);
			}
			return result;
			
		}
		catch (SQLException e){
			throw new DAOException(e.getMessage());
		}
		catch (NamingException e){
			throw new DAOException(e.getMessage());
		}
	}
}
DTO
package br.com.model.cadastro.dto;

public class CadastroProcDTO {
	private String id;
	private String nProc;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getNProc() {
		return nProc;
	}
	public void setNProc(String proc) {
		nProc = proc;
	}


}
Service
package br.com.model.cadastro.service;

import java.util.List;

import br.com.model.cadastro.dto.CadastroProcDTO;
import br.com.model.comum.exception.ServiceException;

public interface CadastroProcService {
	public void incluir(CadastroProcDTO dto) throws ServiceException;
	public List pesquisar(CadastroProcDTO dto) throws ServiceException;
}
Service.Impl
package br.com.model.cadastro.service.impl;

import java.util.List;

import br.com.model.cadastro.dao.CadastroProcDAO;
import br.com.model.cadastro.dao.impl.CadastroProcDAOImpl;
import br.com.model.cadastro.dto.CadastroProcDTO;
import br.com.model.cadastro.service.CadastroProcService;
import br.com.model.comum.exception.DAOException;
import br.com.model.comum.exception.ServiceException;

public class CadastroProcServiceImpl implements CadastroProcService{

	public void incluir(CadastroProcDTO dto) throws ServiceException {
		try{
			CadastroProcDAO cadastro = new CadastroProcDAOImpl();
			cadastro.incluir(dto);
		}
		catch (DAOException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	public List pesquisar(CadastroProcDTO dto) throws ServiceException {
		try{
			CadastroProcDAO cadastro = new CadastroProcDAOImpl();
			return cadastro.pesquisar(dto);
		}
		catch (DAOException e) {
			throw new ServiceException(e.getMessage());
		}
	}
}

4 Respostas

F

alguem?

F

UP!

F

Nada?

F

Resolvido.

public class CadastroProcL {
	
	public List<SelectItem> getCadastro() throws ServiceException {
		//CadastroProcService service = new CadastroProcServiceImpl();
		//cadastro = service.pesquisar();
        List<SelectItem> cadastro = new ArrayList<SelectItem>();
		CadastroProcService service = new CadastroProcServiceImpl();
		List<CadastroProcDTO> cadastroProcDTO =  service.pesquisar();
		for (CadastroProcDTO cad : cadastroProcDTO){
			SelectItem itens = new SelectItem(cad.getId(), cad.getNProc());
			cadastro.add(itens);
			}
		return cadastro;
	}
Criado 1 de agosto de 2008
Ultima resposta 6 de ago. de 2008
Respostas 4
Participantes 1