rendered paste bodypackage action;import dao.DAOBloco;import fswork.Action;import html.Input;import html.InputType;import html.Table;import html.TableCol;import html.TableForm;import html.TableHeader;import html.TableRow;import java.util.HashMap;import java.util.Iterator;import java.util.List;import vo.VOBloco;public class ActionBloco extends Action { public HashMap listarTodos() throws Exception { DAOBloco dao = new DAOBloco(); List<VOBloco> lista = dao.consultarTodos(); if (lista != null) { Table tb = new Table("", 95); TableRow trh = new TableRow(); trh.addTableHeader(new TableHeader("Identificador", "width:20%")); trh.addTableHeader(new TableHeader("Nome", "width:60%")); trh.addTableHeader(new TableHeader("Operação", "width:20%")); tb.addTableRow(trh); StringBuilder sb = new StringBuilder(); sb.append(tb.getHTML()); // Novo Registro TableForm tfn = new TableForm("formNovo", "", 95); TableRow trn = new TableRow(); trn.addTableCol(new TableCol("Novo", "width:20%")); Input nmeNovo = new Input(InputType.TEXT, "pNmeBloco", "", 50); trn.addTableCol(new TableCol(nmeNovo.getHTML(), "width:60%")); Input btInserir = new Input(InputType.BUTTON, "btInserir", "Inserir", "ONCLICK='inserir();'"); trn.addTableCol(new TableCol(btInserir.getHTML(), "width:20%")); tfn.addTableRow(trn); sb.append(tfn.getHTML()); for (Iterator<VOBloco> it = lista.iterator(); it.hasNext();) { VOBloco vo = it.next(); TableForm tbf = new TableForm("form" + vo.getIdt(), "", 95); TableRow trd = new TableRow(); Input idt = new Input(InputType.HIDDEN, "pIdtBloco", vo.getIdt() + ""); trd.addTableCol(new TableCol(idt.getHTML() + vo.getIdt(), "width:20%")); Input nme = new Input(InputType.TEXT, "pNmeBloco", vo.getNme(), 50); trd.addTableCol(new TableCol(nme.getHTML(), "width:60%")); Input btAlterar = new Input(InputType.BUTTON, "btAlterar", "Alterar", "ONCLICK='alterar(\"form" + vo.getIdt() + "\");'"); Input btExcluir = new Input(InputType.BUTTON, "btExcluir", "Excluir", "ONCLICK='excluir(\"form" + vo.getIdt() + "\");'"); trd.addTableCol(new TableCol(btAlterar.getHTML() + " " + btExcluir.getHTML())); tbf.addTableRow(trd); sb.append(tbf.getHTML()); } dados.put("TABELAS", sb.toString()); } return dados; } public HashMap inserir() throws Exception { if (validar()) { VOBloco vo = new VOBloco(); vo.setNme(request.getParameter("pNmeBloco")); DAOBloco dao = new DAOBloco(); if (dao.incluir(vo)) { dados.put("MSG", "Bloco incluído com sucesso."); } else { dados.put("MSG", "Falha na inclusão de bloco."); } } return dados; } public HashMap alterar() throws Exception { if (validar()) { VOBloco vo = new VOBloco(); vo.setIdt(Integer.parseInt(request.getParameter("pIdtBloco"))); vo.setNme(request.getParameter("pNmeBloco")); DAOBloco dao = new DAOBloco(); if (dao.alterar(vo)) { dados.put("MSG", "Bloco alterado com sucesso."); } else { dados.put("MSG", "Falha na alteração de bloco."); } } return dados; } public HashMap excluir() throws Exception { VOBloco vo = new VOBloco(); vo.setIdt(Integer.parseInt(request.getParameter("pIdtBloco"))); DAOBloco dao = new DAOBloco(); if (dao.excluir(vo)) { dados.put("MSG", "Bloco excluído com sucesso."); } else { dados.put("MSG", "Falha na exclusão de bloco."); } return dados; } private boolean validar() { boolean ret = true; if (request.getParameter("pNmeBloco").trim().equals("")) { dados.put("MSG", (dados.get("MSG") == null ? "" : (String) dados.get("MSG")) + "<BR>Nome é campo obrigatório."); ret = false; } return ret; }}