<%@ page session="true" %>
<%@ page import="myApp.Agenda" %>
<%@ page import="myApp.Oggetto" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%!
void add(Agenda agenda, Oggetto oggetto) {
boolean alreadyInCatalogue = false;
for ( Oggetto itemInCatalogue : agenda.getOgg() ) {
if ( itemInCatalogue.getCognome().equals( oggetto.getCognome() ) ) {
alreadyInCatalogue = true;
break;
}
}
if ( ! alreadyInCatalogue ) {
agenda.getOgg().add( oggetto );
}
}
void remove(Agenda agenda, String cognome){
for(int i=0; i<agenda.getOgg().size(); i++){
if( agenda.getOgg().get(i).getCognome().equals(cognome ) ){
agenda.getOgg().remove(i);
break;}
}
}
%>
<html>
<head>
<meta name="Author" content="mine">
<title>Home Agenda</title>
<link rel="stylesheet" href="<%= request.getContextPath() %>/styles/default.css" type="text/css"/>
<script="text/javascript">
function conferma(){
var annulla = window.confirm("L'azione rimuoverà tutti i dati, continuare?");
if(annulla){}
else {}
}
</script>
</head>
<body>
<%@ include file="../fragments/header.jsp" %>
<div id="main" class="clear">
<jsp:useBean id="agenda" class="myApp.Agenda" scope="application" />
<%
String nome=request.getParameter("nome");
String cognome=request.getParameter("cognome");
String email = request.getParameter("email");
String tel = request.getParameter("telefono");
if( request.getParameter("add")!=null && !request.getParameter("add").equals("")){
Oggetto curr = new Oggetto();
curr.setCognome(cognome);
curr.setNome(nome);
curr.setTelefono(tel);
curr.setEmail(email);
add(agenda,curr);
}
else if ( request.getParameter("remove") != null && ! request.getParameter("remove").equals("") ) {
remove(agenda,cognome);
}
if( request.getParameter("remove2") != null && !request.getParameter("remove2").equals("")){
agenda.empty();
}
%>
Welcome to the 'Esempio'project.</p>
Provalooooooooo!</p>
</div>
<div id="cent">
<div id="left" style="float: left; width: 50%">
Aggiungi un contatto o eliminalo </p>
<FORM>
<table>
<tr><td>
Nome:<input type="text" name="nome"/>
</td>
<tr><td>
Cognome:<input type="text" name="cognome"/>
</td>
<tr><td>
E-mail:<input type="text" name="email"/>
</td>
<tr><td>
Telefono:<input type="text" name="telefono"/>
</td>
<tr><td>
<input type="submit" name="add" value="aggiungi" >
<input type="submit" name="remove2" value="rimuovi tutti" onClick="conferma()" >
</td>
</tr></table><FORM></div>
<div id="right" style="float: right; width: 50%">
Agenda corrente:
<table>
<tr>
<th style="width: 25%">Nome: </th>
<th style="width: 25%">Cognome:</th>
<th style="width: 25%">Email:</th>
<th style="width: 25%">Telefono:</th>
</tr>
<c:forEach var="unOgg" items="${agenda.ogg}">
<tr>
<td>${unOgg.nome}</td>
<td>${unOgg.cognome}</td>
<td>${unOgg.email}</td>
<td>${unOgg.tel}</td>
<td>Rimuovi</td>
</tr>
</c:forEach>