You are on page 1of 3

APOYO CODIFICACION.

REFERENCIAS MATERIALIZE

*********************************************************************************************************************

CABECERA:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">


<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>

PARTE INFERIOR:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('select').formSelect();
});
</script>

INDEX

*********************************************************************************************************************

FILA CON CAMPO DE TEXTO:

<div class="row">
<div class="input-field col s12 m12 l12 xl12">
<i class="material-icons prefix">vpn_key</i>
<input type="text" id="txtcod" name="txtcod">
<label for="txtcod">Codigo</label>
</div>
</div>

FILA CON COMBOBOX:

<div class="row">
<div class="input-field col s6">
<select id="cboest" name="cboest">
<option value="Epico">Epico</option>
<option value="Dramatico">Dramatico</option>
<option value="Lirico">Lirico</option>
<option value="Narrativo">Narrativo</option>
</select>
<label for="cboest">Seleccione Estilo</label>
</div>
</div>

FILA CON BOTONES DE OPCION:

<div class="row">
<div class="input-field col s6">
<p>Editorial</p>
<p>
<label>
<input type="radio" name="opedi" id="op1" checked value="Molino" class="with-gap">
<span>Molino</span>
</label>
<label>
<input type="radio" name="opedi" id="op2" value="Santillana" class="with-gap">
<span>Santillana</span>
</label>
</p>
</div>
</div>
FILA CON BOTONES DE ENVIO

<div class="row">
<div class="input-field col s3">
<button name="btnreg" id="btnreg" class="btn waves-effect waves-light" type="submit">
Registrar<i class="material-icons right">save</i>
</button>
</div>
</div>

IMPORTAR CLASES DESDE LA PAGINA:

<%@page import="java.util.ArrayList" %>


<%@page import="modelo.Producto" %>

LISTAR REGISTROS

for (int i = 0; i < lispro.size(); i++) {


Producto p = lispro.get(i);
out.println("<tr>");
out.println("<td>" + p.getCodigo() + "</td>");
out.println("<td> <a href='eliminar.do?codeli="+p.getCodigo()+"'>Pinche Aqui</a></td>");
out.println("</tr>");
}

LISTENER.

*********************************************************************************************************************

public class Listener implements ServletContextListener {


private ArrayList<Producto> lispro = new ArrayList<Producto>();

@Override
public void contextInitialized(ServletContextEvent sce) {
sce.getServletContext().setAttribute("lispro", lispro);
}
....

PROCESAR.

*********************************************************************************************************************

RECIBIR EL ATRIBUTO LISTENER Y ENTREGARSELO AL ARRAYLIST:

ArrayList<Producto> lispro = (ArrayList<Producto>) getServletContext().getAttribute("lispro");

RECIBIR UN CAMPO DE TEXTO Y PASARLO A UNA VARIABLE:

String cod = request.getParameter("txtcod");

CREAR LISTA PARA GUARDAR ERRORES:

ArrayList<String> liserr = new ArrayList<String>();

VALIDACION DE CAMPO VACIO:

if (cod.trim().length() == 0) {
liserr.add("LA CASILLA DEL CODIGO ESTA VACIA");
}
EXISTEN ERRORES EN LA LISTA O NO (GUARDAMOS O MOSTRAMOS ERRORES):

if (liserr.isEmpty()) {
Producto p = new Producto(cc,nom,pp,ss);
lispro.add(p);
getServletContext().setAttribute("lispro", lispro);
response.sendRedirect("index.jsp");
}else{
request.setAttribute("liserr", liserr);
request.getRequestDispatcher("ver_errores.view").forward(request, response);
}

MOSTRAR ERRORES

*********************************************************************************************************************

ArrayList<String> liserr = (ArrayList<String>) request.getAttribute("liserr");


out.println("<h4>Listado de Errores</li>");
for (int i = 0; i < liserr.size(); i++) {
String error = liserr.get(i);
out.println("<p>" + error + "</p>");
}

ELIMINAR REGISTRO

*********************************************************************************************************************

ArrayList<Producto> lispro = (ArrayList<Producto>) getServletContext().getAttribute("lispro");


String cod = request.getParameter("codeli");
int cc = Integer.parseInt(cod);
for (int i = 0; i < lispro.size(); i++) {
Producto p = lispro.get(i);
if (cc == p.getCodigo()) {
lispro.remove(i);
}
}
getServletContext().setAttribute("lispro", lispro);
response.sendRedirect("index.jsp");

You might also like